admin管理员组文章数量:1279188
fiddle here /
I have data from json like so
$scope.info={
"pany1":"this",
"pany2":"is",
"pany3":"sparta"
}
I am using ng-repeat
to print all the data and I want to monotor for changes on the fields.
<input type="text" ng-repeat="item in info" value="{{item}}" monitor-change>
I have a monitorChange directive like this:
.directive('monitorChange', function() {
return {
restrict: 'A',
scope: {changedFlag: '='},
link: function(scope, element, attrs) {
var $el = angular.element(element);
$el.on('keyup', function() {//bind to element
scope.$apply( function() {
scope.changedFlag =true;//on key press value is changed
});
});
}
};
});
When trying to change the data, I receive the error Error: [$pile:nonassign] Expression 'undefined' used with directive 'monitorChange' is non-assignable!
I am printing the data in my view with:
{{changedFlag }}
What is wrong with the code?
fiddle here http://jsfiddle/prantikv/dJty6/36/
I have data from json like so
$scope.info={
"pany1":"this",
"pany2":"is",
"pany3":"sparta"
}
I am using ng-repeat
to print all the data and I want to monotor for changes on the fields.
<input type="text" ng-repeat="item in info" value="{{item}}" monitor-change>
I have a monitorChange directive like this:
.directive('monitorChange', function() {
return {
restrict: 'A',
scope: {changedFlag: '='},
link: function(scope, element, attrs) {
var $el = angular.element(element);
$el.on('keyup', function() {//bind to element
scope.$apply( function() {
scope.changedFlag =true;//on key press value is changed
});
});
}
};
});
When trying to change the data, I receive the error Error: [$pile:nonassign] Expression 'undefined' used with directive 'monitorChange' is non-assignable!
I am printing the data in my view with:
{{changedFlag }}
What is wrong with the code?
Share Improve this question edited Mar 16, 2015 at 13:06 Claies 22.3k4 gold badges55 silver badges80 bronze badges asked Mar 16, 2015 at 12:58 krvkrv 2,9408 gold badges45 silver badges83 bronze badges 2- You should post the actual error message you are receiving. I'll update the question with the full error for you. – Claies Commented Mar 16, 2015 at 13:02
-
2
scope: {changedFlag: '='},
but you're not declaring in the HTML anychanged-flag
attribute. – Omri Aharon Commented Mar 16, 2015 at 13:07
1 Answer
Reset to default 9- As you mentioned
scope: {caretPosition: '='}
in directive definition, we need to passcaret-position="obj.changedFlag"
in the markup. - As
ng-repeat
creates a new scope for each item, it is good to use the Dot notation for the changes to reflect in the controller's scope.
Here is the updated fiddle. http://jsfiddle/dJty6/38/
本文标签: javascriptError Expression 39undefined39 used with directive is nonassignableStack Overflow
版权声明:本文标题:javascript - Error: Expression 'undefined' used with directive is non-assignable - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741218085a2360441.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论