【发布时间】:2016-05-18 13:54:19
【问题描述】:
我的 controller.js 中有一个数组。我需要用户插入输入文本值,如果正确,则显示一件事,如果不同则显示另一件事。我有多个实例,然后我计划使用ng-switch,但不要让我获得变量范围的值。我该如何解决?
INDEX.html
<body ng-app="formAdictos">
<div ng-controller="MyController">
<div ng-repeat="list in lista"></div>
<div ng-switch on="lis">
<input type="text" ng-model="lis">
<div ng-switch-when="{{lista[0]}}">S</div>
<div ng-switch-when={{lista[1]}}>Hola</div>
<div ng-switch-default>Texto para cuando no es ni A ni B</div>
</div>
</div>
</body>
controller.js
function MyController($scope, $http) {
$scope.items = [];
$scope.lista = [];
$http({method : 'GET',url : 'https://api.parse.com/1/classes/cupon',
headers: { 'X-Parse-Application-Id':'XXX',
'X-Parse-REST-API-Key':'XXX'}})
.success(function(data, status) {
for(var i = 0; i < data.results.length; i++){
cupo = data.results[i].cupon50;
$scope.lista[i] = cupo;
}
console.log($scope.lista);
})
.error(function(data, status) {
alert("Error");
});
}
angular.module('formAdictos').controller('MyController', MyController);`
列出一个包含三个值的数组。
lista = ["hi","good","bad"] 这是 http 调用的结果
【问题讨论】:
-
请编辑问题以包含从您的 $http 调用返回的 JSON。
-
$scope.lista = ["hi","good","bad"] 这是结果
标签: javascript html angularjs parse-platform ng-switch