AngularJS 1.6.6 ng重复 文件 学期: {{v.SemesterId}} var-app=angular.module('myApp',[]); 应用控制器('mc1',功能($scope) { $scope.semesters='[{“学期ID”:“2017年秋季”},{“学期ID”:“2017年春季”}]; })
当我运行此页面时,我得到错误:[ngRepeat:dups]。我试图按$index添加曲目,但完全不起作用 谁能告诉我原因吗 编辑:对不起,我没有解释清楚。我使用C#中的库将datatable对象转换为json字符串。然后通过web api将其传递到web页面。在脚本中,我使用angular.jsonFrom(response.data) 浏览器中的响应是“[{\'SemesterId\”:\'Fall 2017\”},{\'SemesterId\“:\'Spring 2017\”}”。我已经修复了这个错误,但我不知道为什么 谢谢大家。附:正确答案如下AngularJS 1.6.6 ng重复 文件 学期: {{v.SemesterId}} var-app=angular.module('myApp',[]); 应用控制器('mc1',功能($scope) { $scope.semesters='[{“学期ID”:“2017年秋季”},{“学期ID”:“2017年春季”}]; }),angularjs,Angularjs,当我运行此页面时,我得到错误:[ngRepeat:dups]。我试图按$index添加曲目,但完全不起作用 谁能告诉我原因吗 编辑:对不起,我没有解释清楚。我使用C#中的库将datatable对象转换为json字符串。然后通过web api将其传递到web页面。在脚本中,我使用angular.jsonFrom(response.data) 浏览器中的响应是“[{\'SemesterId\”:\'Fall 2017\”},{\'SemesterId\“:\'Spring 2017\”}”。我已经修
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.6/angular.min.js"></script>
<title>Document</title>
</head>
<body ng-app="myApp" ng-controller="mc1">
<label class="control-label">Semester:</label>
<select ng-model="selectedSemesters" ng-change="selectedSemesterChanged()" class="form-control">
<option value="{{v.SemesterId}}" ng-repeat="v in semesters">{{v.SemesterId}}</option>
</select>
<script>
var app=angular.module('myApp',[]);
app.controller('mc1',function($scope)
{
$scope.semesters='[{"SemesterId":"Fall 2017"},{"SemesterId":"Spring 2017"}]';
})
</script>
</body>
</html>
{x.SemesterId}
{x.SemesterId}
var app=angular.module('mySelect',[]);
app.controller('myCt',['$scope',函数($scope){
$scope.data1=angular.fromJson(“[{\'SemesterId\':\'Fall 2017\',{\'SemesterId\':\'Spring 2017\'”);
}]);
您传递的是字符串而不是数组。因此,ng repeat在迭代时显示错误。
线下变更
<body ng-app="mySelect" ng-controller="myCt">
<select ng-model="mySelected1">
<option ng-repeat="x in data1">{{x.SemesterId}}</option>
</select>
<select ng-model="mySelected2" ng-options="x.SemesterId for x in data1">{{x.SemesterId}}</select>
<label ng-model="data1"></label>
<script>
var app = angular.module('mySelect', []);
app.controller('myCt', ['$scope', function ($scope) {
$scope.data1=angular.fromJson('[{\"SemesterId\":\"Fall 2017\"},{\"SemesterId\":\"Spring 2017\"}]');
}]);
</script>
</body>
到
您传递的是字符串而不是数组。因此,ng repeat在迭代时显示错误。 线下变更
<body ng-app="mySelect" ng-controller="myCt">
<select ng-model="mySelected1">
<option ng-repeat="x in data1">{{x.SemesterId}}</option>
</select>
<select ng-model="mySelected2" ng-options="x.SemesterId for x in data1">{{x.SemesterId}}</select>
<label ng-model="data1"></label>
<script>
var app = angular.module('mySelect', []);
app.controller('myCt', ['$scope', function ($scope) {
$scope.data1=angular.fromJson('[{\"SemesterId\":\"Fall 2017\"},{\"SemesterId\":\"Spring 2017\"}]');
}]);
</script>
</body>
到
请查看此Plunkr的工作情况
$scope.semesters=[{"SemesterId":"Fall 2017"},{"SemesterId":"Spring 2017"}];
文件
学期:
{{v.SemesterId}}
var-app=angular.module('myApp',[]);
应用控制器('mc1',功能($scope)
{
$scope.semesters=[{“学期ID”:“2017年秋季”},{“学期ID”:“2017年春季”}];
})
在您的
学期
变量中没有可重复的内容,因为数组声明周围有引号。请查看此Plunkr的工作情况
$scope.semesters=[{"SemesterId":"Fall 2017"},{"SemesterId":"Spring 2017"}];
文件
学期:
{{v.SemesterId}}
var-app=angular.module('myApp',[]);
应用控制器('mc1',功能($scope)
{
$scope.semesters=[{“学期ID”:“2017年秋季”},{“学期ID”:“2017年春季”}];
})
您的
学期
变量中没有可重复的内容,因为数组声明周围有引号。对于select,我认为最好使用ng选项
对于select,我认为最好使用ng选项