【发布时间】:2016-01-27 04:41:14
【问题描述】:
我不明白为什么,没有什么异常。
我有:
控制器
define([
'underscore',
'json!data/options.json'
], function (_, options) {
"use strict";
var parseValue = function (val, type) {
if (!type || type === "text" || type === "password") {
return val;
}
switch (type) {
case 'checkbox':
return !!val;
case 'number':
return parseInt(val);
default:
throw new Error("Unknow type ", type);
}
};
return [
"$scope",
"OptionsService",
function ($scope, OptionsService) {
$scope.ops = _.map(options, function (op, key) {
op.id = key;
op.value = OptionsService.get(key, op.def);
return op;
});
$scope.update = function (opId) {
var op = _.findWhere($scope.ops, {
id: opId
});
OptionsService.set(opId, parseValue(
op.value,
op.type));
};
console.log("Options", $scope.ops);
}
];
});
模板
<ion-content>
<p>{{ops}}</p>
<div class="list">
<label
ng-repat="op in ops"
class="item item-input item-floating-label">
{{op}}
</label>
</div>
console.log 显示 $scope.ops 是正确的:
Options [Object, Object]
<p>{{ops}}</p> 显示正确的 json。
但是angular编译出来的结果是:
<div class="scroll">
<p class="ng-binding">[{"desc":"Max notifications","type":"number","def":10,"min":0,"max":null,"id":"notifications.max-notifications","value":10},{"desc":"Auto sync","def":false,"type":"checkbox","id":"remote.auto-sync","value":false}]</p>
<div class="list">
<label ng-repat="op in ops" class="item item-input item-floating-label ng-binding">
</label>
</div>
</div>
我缺少什么?
【问题讨论】:
-
您将
ng-repeat拼错为ng-repat。这可能会导致您的问题。 -
哦,f...,我是个f...白痴。谢谢
标签: javascript angularjs ionic-framework angularjs-ng-repeat