我使用 angular.js 和 require.js 编写一个网络应用程序。 但是 ng-repeat 不起作用! Chroem 仅在使用开发者工具时显示注释。
HTML 代码:
<div class="over-layout">
<ul class="list">
<li ng-repeat="item in items" >
{{item}}
</li>
</ul>
</div>
<div id="page">
<div class="header">{{title}}</div>
<div class="page-view" ng-view></div>
<div id="footer">
参考: <a href="http://tutorials.jenkov.com/svg/simple-svg-example.html" title="Github">jenkov.com</a>
{{items[0].title}}
</div>
</div>
JS 代码:
app.controller('HomeCtrl', function ($scope) {
// 文章目录
$scope.index = 0;
$scope.title = '开始学习SVG';
$scope.items = [
{
'title': '开始学习SVG',
'hash': 'home'
},
{
'title': 'svg与g标签',
'hash': 'svg-el-and-g'
}
];
$scope.MAX = $scope.items.length;
$('.bt-menu-trigger').toggle(function(){
$(this).parent().addClass('bt-menu-open');
$('.over-layout').addClass('active');
},function(){
$(this).parent().removeClass('bt-menu-open');
$('.over-layout').removeClass('active');
});
$scope.select = function($e,item){
$scope.title = $scope.list[item].title;
}
});
chrome 显示:
<div class="over-layout">
<ul class="list">
<!-- ngRepeat: item in items -->
</ul>
</div>
谢谢!!
最佳答案
您当前范围内似乎没有可用的 items 对象。我不明白你在哪里包括 Controller 。尝试用以下内容包装整个 html block :
<div data-ng-controller="HomeCtrl">
<!-- your existing content -->
</div>
关于javascript - ng-repeat 不起作用,但可以在页面上获取 $scope.items 的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28780288/