【发布时间】:2016-03-09 14:52:08
【问题描述】:
你好,我创建了简单的 AngularJS 应用程序,我有两个按钮(创建新手机和创建新类别),我保存了我的类别进入数组使用工厂:
myApp.factory('categoriesStorage', function () {
var storage = [];
var categories = ["Apple","HTC"];
storage.addCategory = function (categoryTest) {
categories.push(categoryTest);
console.log(categories);
}
storage.getCategories = function()
{
return categories;
}
return storage;
});
在 Add New Phone 表单我有 dx-select-box -element:
<div class="dx-label">Phone Name</div>
<div dx-select-box="nameOfPhone" ng-model="phoneName"></div><br/><br />
为了从数组中获取元素,我使用 HomeController.js 中的下一个代码 //弹出的手机名称选择框
$scope.nameOfPhone = {
items: categoriesStorage.getCategories()
};
直到我改变焦点或关闭添加新类别表单时,新元素添加到数组中但不显示到选择框中。
感谢您的回答!
【问题讨论】:
-
视图添加类别和电话之间是否有通用控制器?
标签: arrays angularjs factory devextreme