我知道標題很糟糕,但情況本身足夠奇怪,無法使用該標題。因此,這裏是我的玉文件 - 模板:指令範圍變量不能在Jade中工作
img.picture(ng-show='user.info.profilePicUrl', ng-src='{{user.info.profilePictureUrl}}')
img.picture(ng-show="!user.info.profilePicUrl", ng-src="dummyuser.png")
.basicinfo
h1.fullname
a(href='profile/{{user.info.username}}') {{user.info.fullName}}
p.description {{user.info.bio}}
span.additional
a.website(href='{{user.info.website}}') {{user.info.website}}
a.location(href='#') {{user.info.location}}
.follow
.count {{user.followedBy.length}} Followers
follow(to-follow-username="user.info.username")
在指令:
scope: {
user: "="
},
controller: function($scope){
var request = $http({
method: "get",
url: "https://stackoverflow.com/users/" + $scope.user.userID + "/getInfo",
});
request.success(function(data, status, headers, config){
$scope.user.info = data;
console.log($scope.user);
});
request.error(function(data, status, headers, config){
console.log("Status");
console.log(status);
});
},
templateUrl: "/templates/follower"
因此,這裏的問題:當我打開包含這個模板和指令的頁面,用戶被傳遞到翡翠以上,並且它的每一行都分析user
的數據,但profilePicUrl
和user.info.username
除外。 user.info.username
在行a(href='profile/{{user.info.username}}') {{user.info.fullName}}
中正常工作,但它不起作用 - 以undefined
的形式出現 - 在行follow(to-follow-username="user.info.username")
中。
img.picture(ng-show='user.info.profilePicUrl', ng-src='{{user.info.profilePictureUrl}}')
img.picture(ng-show="!user.info.profilePicUrl", ng-src="dummyuser.png")
.basicinfo
h1.fullname
a(href='profile/{{user.info.username}}') {{user.info.fullName}} //The username is actual username - Works Here
p.description {{user.info.bio}}
span.additional
a.website(href='{{user.info.website}}') {{user.info.website}}
a.location(href='#') {{user.info.location}}
.follow
.count {{user.followedBy.length}} Followers
follow(to-follow-username="user.info.username") //Doesn't work here
什麼'p {{用戶}}'顯示? – KyleK 2015-04-05 21:30:42
是的,它只打印沒有'user.info'的'user'。我根據這個編輯了這個問題。添加了我的指令的控制器功能。我怎樣才能使http調用同步? – mtndesign 2015-04-07 10:33:20
我用諾言(然後())來完成這個,但錯誤仍然存在。即使數據來源於Jade,Jade表達式也會解析它,而'ng- *'不會:'ng-show =「!user.info.profilePicUrl」'不起作用。 – mtndesign 2015-04-08 10:13:31