指令范围变量在Jade中不起作用

时间:2015-04-05 19:44:16

标签: angularjs angularjs-directive pug

我知道标题很糟糕,但情况本身很奇怪,有这个头衔。所以这是我的玉文件 - 模板:

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: "/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"

所以这是问题:当我打开包含此模板和指令的页面时,用户将被传递给上面的jade,并且它的每一行都会解析来自user的数据,profilePicUrl除外,和user.info.usernameuser.info.usernamea(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

1 个答案:

答案 0 :(得分:1)

不要使HTTP cal同步,而是在成功时重新应用范围修改:

request.success(function(data, status, headers, config){
  $scope.$apply(function () {
    $scope.user.info = data;
  });
}); 
相关问题