2014-09-12 61 views
0

下面是粗糙的代码不完全语法角JS,控制器变量不能够读取指令

/JS文件 (函数(){

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; 
      }); 
    }); 

//响应是象 [{”基本“:{”node_id“:”8“,”title“:”NEWS主题“,”别名“:”新闻主题“,”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文件,显示的所有节点上,

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

我想templateUrl像 “URL/GET_NAME/12345”, 但它正在像“URL/GET_NAME/{{x.basic.created_by}}”

+0

你的鳕鱼e是一个混乱,无意义的混乱。请创建一个[MCVE](http://stackoverflow.com/help/mcve),其中显示了它使用的代码和数据。 – 2014-09-12 12:04:01

+0

@DarkFalcon现在清楚了吗? – aparna 2014-09-12 12:20:10

+0

是的,除了确切的问题,更清晰。你无法读取什么变量? – 2014-09-12 12:22:59

回答

0

<username userid="{{x.basic.created_by}}"></username>

写取下花括号像<username userid="x.basic.created_by"></username>