错误:[编译:nonassign ]表达'定义'用于指导'myfacebook '不可转让

harshit提出了一个问题:Error: [$compile:nonassign] Expression 'undefined' used with directive 'myFacebook' is non-assignable,或许与您遇到的问题类似。

回答者bmleite给出了该问题的处理方式:

The problem is that you are not defining the attribute friendsin the directive element <div my-facebook></div>.

When you define the directive's scope like this:

scope: {
    permissions: '@',
    myFriends: '=friends'
}

You are basically saying:

  • Bind to the local scope's permissionsproperty the value of DOM attribute with the same name
  • Set up bi-directional binding between the local scope's myFriendsproperty and the parent scope's friendsproperty

Since you are not defining the attribute friendsin the DOM, Angular cannot create the bi-directional binding and throws the error. More information here.

Define the friendsattribute on your DOM and it should fix the problem:

<div my-facebook friends="friendList"></div>

And, for example, on the controller:

app.controller('Ctrl', function($scope) {
  $scope.friendList = [];
});

希望本文对你有帮助,欢迎支持JavaScript中文网

原文链接:stackoverflow.com

上一篇:jQuery的“hasparent”
下一篇:我如何使用正则表达式来指定字符后得到的所有字符,如逗号(“,”)

相关推荐

官方社区

扫码加入 JavaScript 社区