Directives scope variable does not work in Jade

0xmtn

I know the title is bad but the situation itself is weird enough to have this title. So here is my jade file - template:

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")

In the directive:

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"

So here is problem: When I open the page that contains this template and directives, the user is passed to jade above, and every line of it parses the data from user, except profilePicUrl, and user.info.username. The user.info.username work fine in the line a(href='profile/{{user.info.username}}') {{user.info.fullName}}, but it doesn't work - comes as undefined - in the line 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
KyleK

Do not make the HTTP cal synchronous but re-apply the scope modifications on success:

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Why does printing a variable in global scope work, but modifying it does not?

From Dev

Why does printing a variable in global scope work, but modifying it does not?

From Dev

How does one preserve scope with nested directives?

From Dev

How does one preserve scope with nested directives?

From Dev

meteor Jade iteration does not work

From Dev

Using a local variable outside of its declaring scope; why does this work?

From Dev

How does variable scope work within the Mocha test framework?

From Dev

Prolog: how does variable instantiating work, what is the scope of local variables

From Dev

Prolog: how does variable instantiating work, what is the scope of local variables

From Dev

Angular $scope does not work

From Dev

Angular $scope does not work

From Dev

Why does it work with $scope but not with `this`?

From Dev

Scope in directives

From Dev

Scope in directives

From Dev

Why --watch Jade option does not work?

From Dev

Why does this jade template not work with commenting?

From Dev

Meteor JS Jade template does not work as expected

From Dev

Jade Syntax does not work with pug : Node Js

From Dev

How does scope work in Io?

From Dev

How does scope work in Ruby?

From Dev

Why does the scope work like this?

From Dev

problems with the scope variable over communication between the directives in angularjs

From Dev

Why does $scope.$watch work but $scope.$watchCollection does not?

From Dev

How does document.ready work with angular element directives?

From Dev

Scope inheritance for angular directives

From Dev

controllerAs with directives and isolated scope

From Dev

Scope Isolation & nested directives

From Dev

AngularJS : directives and scope

From Dev

Isolated scope for directives

Related Related

  1. 1

    Why does printing a variable in global scope work, but modifying it does not?

  2. 2

    Why does printing a variable in global scope work, but modifying it does not?

  3. 3

    How does one preserve scope with nested directives?

  4. 4

    How does one preserve scope with nested directives?

  5. 5

    meteor Jade iteration does not work

  6. 6

    Using a local variable outside of its declaring scope; why does this work?

  7. 7

    How does variable scope work within the Mocha test framework?

  8. 8

    Prolog: how does variable instantiating work, what is the scope of local variables

  9. 9

    Prolog: how does variable instantiating work, what is the scope of local variables

  10. 10

    Angular $scope does not work

  11. 11

    Angular $scope does not work

  12. 12

    Why does it work with $scope but not with `this`?

  13. 13

    Scope in directives

  14. 14

    Scope in directives

  15. 15

    Why --watch Jade option does not work?

  16. 16

    Why does this jade template not work with commenting?

  17. 17

    Meteor JS Jade template does not work as expected

  18. 18

    Jade Syntax does not work with pug : Node Js

  19. 19

    How does scope work in Io?

  20. 20

    How does scope work in Ruby?

  21. 21

    Why does the scope work like this?

  22. 22

    problems with the scope variable over communication between the directives in angularjs

  23. 23

    Why does $scope.$watch work but $scope.$watchCollection does not?

  24. 24

    How does document.ready work with angular element directives?

  25. 25

    Scope inheritance for angular directives

  26. 26

    controllerAs with directives and isolated scope

  27. 27

    Scope Isolation & nested directives

  28. 28

    AngularJS : directives and scope

  29. 29

    Isolated scope for directives

HotTag

Archive