gpt4 book ai didi

javascript - 错误 : [$compile:nonassign] Expression 'undefined' used with directive 'myFacebook' is non-assignable

转载 作者:IT王子 更新时间:2023-10-29 03:03:56 28 4
gpt4 key购买 nike

我正在用 angularjs 编写一个指令并得到上面提到的错误。我正在使用一本书中的代码。

.directive('myFacebook', [function(){
return {
link: function(scope,element,attributes) {
(function(d) {
var js, id = 'facebook-jssdk',
ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {
return;

}
js = d.createElement('script');
js.id = id;
js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
// Initialize FB
window.fbAsyncInit = function() {
FB.init({

appId: 'xxxx', //birthday reminder
status: true, // check login status
cookie: true, // enable cookies to access the session
xfbml: false // parse XFBML
});
//Check FB Status
FB.getLoginStatus(function(response) {
xxxx
});
};
scope.username='';
},
scope: {
permissions: '@',
myFriends: '=friends'
},
controller: function($scope) {
$scope.loadFriends = function() {
FB.api('/me/friends?fields=birthday,name,picture', function(response) {
$scope.$apply(function() {
$scope.myFriends = response.data;
});
});
}
},

template:'Welcome {{username}}'
}}])

我在

处遇到错误
 $scope.$apply(function() {
$scope.myFriends = response.data;
});

HTML代码

<div my-facebook></div>
<h1> My Friend's Birthday Reminder</h1>
<div ng-repeat="friend in myFriends">
{{friend.name}}
</div>

最佳答案

我的解决方案在这里很难找到,但更容易实现。我不得不将其更改为等同于(请注意,问号使该属性成为可选属性。在 1.5 之前,这显然不是必需的)。

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

关于javascript - 错误 : [$compile:nonassign] Expression 'undefined' used with directive 'myFacebook' is non-assignable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25627683/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com