青春有我
如果你非要这么做的话,应该用引用类型:var testapp = angular.module('testapp', []);
testapp.controller('parentController', ['$scope', '$window', function($scope, $window) { console.log('parentController scope id = ', $scope.$id);
$scope.primary1Label = 'Prime1';
$scope.test= { test2: 222 };
$scope.onPrimary1Click = function() {
$window.alert('Primary1 clicked');
};
}]);
testapp.directive('primary', function() { return { restrict: 'C', scope: false,
link: function(scope, element, attrs) {
alert(scope.test.test2);
element.addClass('btn btn-primary');
}
}
});
testapp.directive('buttonBar', function() { return { restrict: 'EA', template: '<div class="span4 well clearfix"><div class="pull-right" ng-transclude></div></div>', replace: true, transclude: true, scope: false,
link: function(scope, element, attrs) {
scope.test.test2 = 111; //alert(scope.primary1Label);
}
};
});