角度js,控制器变量无法读取指令

时间:2014-09-12 11:59:10

标签: angularjs-scope

下面是粗略代码而不是完全语法

/ JS FILE (function(){

var app     = angular.module('ngABC', []);
var nodes     = [];



 Here is the controller to get all node fron server using http
  app.controller('nodesController', function($scope,$http){
           $http({
                url:        $url,
                method:     "POST",
                data:       postData,
                headers :   {'Content-Type': 'application/x-www-form-urlencoded'}

            }).success(function(response) {  
              $Scope.nodes = response;
           });
  });

//响应就像 [{" basic":{" node_id":" 8"," title":" NEWS TOPIC",& #34;别名":" news-topic"," created_by":12345"}}] ........

This is the directive to get node owner's user name.
app.directive('username', function() { 
   restrict       = 'E';
    templateUrl    = function(ent,attr){ 
          return url+attr.userid; 
                 }      

});

// ========这是.php文件,显示所有NODE,

<div ng-repeat="x in nodes">
          {{ x.basic.node_id}}                                 // printing as "8"
          {{ x.basic.title}}                                   // printing "NEWS TOPIC"
         <username userid="{{x.basic.created_by}}"></username>        

         //Here need's owner Name. SO i am using Directive ANd 
         by templateUrl and going to server with userid to get his NAME  
         Directive should take user_id as "12345" but taking as "{{x.basic.created_by}}"



</div>

我想要&#34; url / get_name / 12345&#34;这样的templateUrl, 但它就像&#34; url / get_name / {{x.basic.created_by}}&#34;

1 个答案:

答案 0 :(得分:0)

删除你的花括号 <username userid="{{x.basic.created_by}}"></username>

将其写为<username userid="x.basic.created_by"></username>