[英]My Angular directive is not getting data from controller
我有这个控制器
.controller('Main', ['$scope', function ($scope) {
$scope.uiState = {'name': 'test'};
}])
和指令是这样的
scope: {uiState: '='},
link: function(scope, element, attrs) {
console.log(scope.uiState) // coming as undefined
}
我正在这样使用
<my-dir uiState="uiState"> </my-dir>
我认为我的指令正在控制器填充该数据之前被编译。
有任何想法吗
我现在看到萤火虫中出现此错误
Error: [$compile:nonassign] Expression 'undefined' used with directive 'my-dir' is non-assignable!
您是否尝试过:范围:{uiState:'= uiState'}?
在这里,您的控制器根本没有被调用。 为了进行调用,必须使用ng-controller至少包含一个元素。 您可以将其更改为
<my-dir uiState="uiState" ng-controller="Main"> </my-dir>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.