即时使用带有模板url的角度js中的自定义指令代码链接如下。问题是ngRpeat不能与模板网址一起工作,如果我将ngRepeat传递给元素,那么它不起作用,但如果我传递模板,它会自行工作。在自定义指令模板中使用角度Js ng-repeatUrl
https://github.com/Rishabh-Ahuja/angularCustomDirectiveNgRepeat
即时使用带有模板url的角度js中的自定义指令代码链接如下。问题是ngRpeat不能与模板网址一起工作,如果我将ngRepeat传递给元素,那么它不起作用,但如果我传递模板,它会自行工作。在自定义指令模板中使用角度Js ng-repeatUrl
https://github.com/Rishabh-Ahuja/angularCustomDirectiveNgRepeat
更新:
以下是你写在main.html中
<search-results customers-d ="customers" ng-repeat="CM in customersD></search-results>
下面的代码是你写的指令SearchResult所:
myApp.directive('searchResults', function() {
return {
templateUrl: 'directives/search.html',
scope: {
customersD: '=',
}
}
});
Followin g是你写的主控制器:
myApp.controller('mainController', ['$scope', '$log', function($scope, $log) {
$scope.customers = [{ name:'Rishabh'},{name:'Krishna'}]
}]);
而且search.html如下:
<a href="#" class="list-group-item">
<h4 class="list-group-item-heading"> hi </h4>
<p class="list-group-item-text">{{CM.name}}</p>
</a>
现在事情你做错了:
我认为您对范围的理解不正确。如果您在这里提问之前已经阅读足够的内容,那将会很好。 :)
以前的答案: 你缺少在NG-重复收盘报价和使用错误的变量 操作如下:在
<search-results customers-d ="CM" ng-repeat="CM in customers"></search-results>
补充说,报价和你的变量仍然不显示名称,并作为PLZ解释变更变量的原因 –
嘿Pranav感谢您的答复!您的第二点说在main.html中尝试访问customersD,而mainController的$ scope中没有定义名为customersD的数组。但这就是为什么我已经定义了客户D访问客户对象 –
'customers-d =“customers”'把客户'对象传递给指令,并且可以通过'customersD'在指令中访问,但是您尝试重复的数组是'customersD',它不在mainController的范围内。 所以没有循环执行,没有任何显示。 – pranavjindal999
main.html中
<div class="list-group">
<search-results customers-d ="customers" ng-repeat="CM in customers"></search-results>
</div>
指令的变化app.js
myApp.directive('searchResults', function() {
return {
restrict : "AE",
templateUrl: 'directives/search.html'
}
});
添加小提琴问题 –