[英]AngularJS Directive Scope Data Ng-Repeat
我正在将数据从应用程序传递到指令并尝试呈现通过 $http 结果传递的数据。 当我将数组记录到指令的作用域中时,我可以看到它的值,但是我无法获取要呈现的列表项。
import angular from 'angular';
(function () {
'use strict';
angular
.module('app', [])
.controller('HomeCtrl', ['$http', '$scope', HomeCtrl])
.directive('animals', [
'$http',
function ($http) {
return {
restrict: 'E',
controller: function ($scope) {
console.log('&&&');
console.log($scope);
},
template:
'<li class="service-item ng-repeat="animal in testData">' +
'{{animal.label}}' +
'</li>'
};
}
]);
/**
* Home controller.
* @param {*} $scope
*/
function HomeCtrl($http, $scope) {
$scope.testData = [];
//get mock data for testData
$http.get('lib/testData.json').then(function (response) {
$scope.testData = response.data;
});
}
})();
http://plnkr.co/edit/rY0ns6RyOJS82f28?open=lib%2Fscript.js&deferRun=1
你缺少一个双引号,它是li class="service-item"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.