javascript - AngularJS 指令范围数据 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"
推荐阅读
- pascal - 如果函数/过程无法执行,则返回错误消息
- java - 什么是未来
? - maven - 使用 JavaFX 和 Maven 在文件夹 lib 中构建具有外部依赖项的项目
- tfs - 在签入 tfs 时,不会提示门控签入构建。直接办理入住。
- admob - AdMob 和 GDPR 选择哪些广告技术提供商?
- javascript - 如何实现长滚动行为
- video - 自动视频创建 API
- node.js - 即使电子邮件未送达也能成功响应
- android - 如何使用 DevicePolicyManger API 中的 installCaCert 方法?
- r - 轴标签大于ggplot2中的绘图输出