AngularJS:为什么';重复工作?
请查看以下代码:AngularJS:为什么';重复工作?,angularjs,Angularjs,请查看以下代码: <html lang="en" > <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> <script src="app.js"></script> </head> <body ng-app="flexbox" >
<html lang="en" >
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<script src="app.js"></script>
</head>
<body ng-app="flexbox" >
<div id="wrapper" ng-controller="flex-ctrl as ctrl">
<div id="aside">
<p ng-repeat="item in ctrl.buttons"> {{item}} </p>
</div>
</div>
</body>
</html>
var app = angular.module("flexbox", []);
app.controller("flex-ctrl", ['$scope', function($scope) {
$scope.buttons = ['a','b', 'c'];
}]);
{{item}
var app=角度模块(“flexbox”,[]);
app.controller(“flex-ctrl”、[“$scope”、函数($scope){
$scope.buttons=['a','b','c'];
}]);
我希望看到三个
项目。然而,看起来ng repeat被忽略了,我看到了一个空页面
你知道有什么问题吗
为方便起见:您的变量位于
$scope
中,因此您可以使用以下命令循环它:
<p ng-repeat="item in buttons"> {{item}} </p>
{{item}
而不是
<p ng-repeat="item in ctrl.buttons"> {{item}} </p>
{{item}
您的变量位于
$scope
中,因此您可以使用以下命令循环它:
<p ng-repeat="item in buttons"> {{item}} </p>
{{item}
而不是
<p ng-repeat="item in ctrl.buttons"> {{item}} </p>
{{item}
使用
this.buttons
而不是$scope.buttons,因为您使用的是控制器作为
语法
var-app=angular.module(“flexbox”,[]);
app.controller(“flex-ctrl”、[“$scope”、函数($scope){
this.buttons=['a','b','c'];
}]);代码>
{{item}
使用this.buttons
而不是$scope.buttons,因为您使用的是控制器作为
语法
var-app=angular.module(“flexbox”,[]);
app.controller(“flex-ctrl”、[“$scope”、函数($scope){
this.buttons=['a','b','c'];
}]);代码>
{{item}
由于您使用的是控制器作为语法,因此可以按如下方式更改ctrl键:
var app = angular.module("flexbox", []);
app.controller("flex-ctrl", [function() {
var vm = this;
vm.buttons = ['a','b', 'c'];
}]);
希望对您有所帮助。因为您使用的是控制器作为语法,所以您可以像这样更改ctrl键:
var app = angular.module("flexbox", []);
app.controller("flex-ctrl", [function() {
var vm = this;
vm.buttons = ['a','b', 'c'];
}]);
希望能有帮助