通过控制器将数据传递给Angular指令。
通过控制器将数据传递给Angular指令。
我正在使用Angular 1.5版本来构建一个指令,可以在不同的情况下使用。我想要能够将控制器中的数据作为对象传递给指令。我的设置大致如下:\n控制器:\n
function ControllerWrapper($scope, $location, $window){ $scope.depth= 99; $scope.filter = {filters: [{column: 'stage', values: ['Closed']}]}; }
\nHTML:\n
\n指令返回:\n
return { restrict: 'E', templateUrl: function(element, attributes) { return attributes.templateUrl; }, link: function(scope, element, attributes) { var obj = scope.$eval(attributes.filters); var dir = scope.$eval(attributes.dir); scope.$watch("filters",function(newValue,oldValue) { if(scope.vm.dir != null){ scope.vm.dir.rows = scope.filterTreeGrid(); } }, true); }, controller: DirectiveController, controllerAs: 'vm', bindToController: true, scope: { maxDepth: '@', filters: '=?' } };
\n根据我所了解的,filters: \'=\'
应该足以传递数据,但在解析之后,我得到了一个空值。有什么建议吗?