Angularjs 为什么ng repeat不能正常工作?
我用Angularjs 为什么ng repeat不能正常工作?,angularjs,angularjs-directive,angularjs-scope,Angularjs,Angularjs Directive,Angularjs Scope,我用ng repeat循环一个数组,但它只显示{{}中写入的内容 控制台中没有任何错误,尽管它没有正确显示。。。 这是密码 <html ng-app="mittens"> <head> <title>Mittens</title> <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">
ng repeat
循环一个数组,但它只显示{{}
中写入的内容
控制台中没有任何错误,尽管它没有正确显示。。。
这是密码
<html ng-app="mittens">
<head>
<title>Mittens</title>
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">
<script type="text/javascript" href="angular.min.js"></script>
<script type="text/javascript" href="mittens.js"></script>
</head>
<body ng-controller="mittensController">
<div class="container">
<h3 ng-repeat="meow in meows">{{meow}}</h3>
</div>
</body>
实际上,mittens.js的参考链接加载错误。您应该使用
src
而不是href
HTML:
更新:这里是Plunker,如果你想参考
ng repeat
指令适用于数组或对象,但您试图使用的数组中只有一个定义不正确的对象
Javascript对象的定义如下:{foo:'Some bar',bar:'Some foo'}
因此,请尝试更改代码,如下所示:
var-app=angular.module('mittens',[]);
应用控制器('mittensController',功能($scope){
$scope.meows=[//像SSH说的那样尝试这个{{meow}
。您已经将数据打包到数组的第一列中。实际上它不起作用…我只是用方括号尝试了一下…但它不起作用…删除{}另外。不,它不起作用@McBomanI改变了你提到的方式,但似乎没有任何作用..没有控制台端错误…@WebFlash立即尝试。你提到href。它应该在哪里
,即“src”而不是“href”@WebFlash如果起作用,请接受其他人参考的答案,从如何做?我想对所有答案进行投票b但是它向我显示了一个错误,有15个声誉…@WebFlash你不需要投票,你只需要接受答案实际上它不起作用…我已经做了所有的事情,我以前也做过…但是在这种情况下没有任何错误,但它不起作用…顺便说一句,我在“源”选项卡中找不到这两个js文件…可以吗这是个问题吗?我找到了解决方案……我在链接js文件时使用了href而不是src……顺便说一句……谢谢……)@shashank
var app = angular.module('mittens',[]);
app.controller('mittensController',function($scope){
$scope.meows = [{
'This is first sentence',
'This is second sentence',
'This is third sentence',
'This is fourth sentence'
}];
});
<html ng-app="mittens">
<head>
<title>Mittens</title>
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">
<script type="text/javascript" href="angular.min.js"></script>
<script src="mittens.js"></script>
</head>
<body ng-controller="mittensController">
<div class="container">
<h3 ng-repeat="meow in meows">{{meow}}</h3>
</div>
</body>
var app = angular.module('mittens',[]);
app.controller('mittensController',function($scope){
$scope.meows = [
'This is first sentence',
'This is second sentence',
'This is third sentence',
'This is fourth sentence'
]; //removed {} braces
});