{{myItem}}
为什么当我尝试分配一个我得到的新变量或输出到我得到的控制台时,我从我的 with 但在我的控制器中获取数据绑定的值undefined
。
这是我的控制器:
var controllers = angular.module("myItem.controllers", []);
controllers.controller('myItemController', function ($scope, MyItemService) {
$scope.version_model = null;
$scope.itemGroup_model = null;
$scope.item_model = null;
$scope.myItem = null;
$scope.versions = null;
$scope.itemGroups = null;
$scope.hierarchies = null;
$scope.init = function () {
$scope.myItem = MyItemService.getMyItem();
console.log("myItem => id= " + $scope.myItem.versionID + " requestTypeID: " + $scope.myItem.requestTypeID);
$scope.versions = MyItemService.getVersions();
$scope.version_model = $scope.myItem.versionID;
console.log("version_model :" + $scope.version_model + "scope.myItem.versionID : " + $scope.myItem.versionID);
$scope.itemGroups = MyItemService.getItemGroups();
$scope.itemGroup_model = $scope.myItem.itemGroup;
console.log("itemGroup_model :" + $scope.itemGroup_model + " scope.myItem.itemGroup : " + $scope.myItem.itemGroup);
$scope.hierarchies = MyItemService.getItemList($scope.itemGroup_model);
$scope.item_model = $scope.myItem.itemName;
console.log("item_model :" + $scope.item_model + " scope.myItem.itemName : " + $scope.myItem.itemName);
}
$scope.getItems = function (group) {
$scope.hierarchies = MyItemService.getHierarchyList(group);
}
每当我尝试从 $scope.myitem 分配任何东西时,我都会一直不确定。我已经尝试在 init 内部进行设置,在 init 外部进行设置。除了_model
值未定义的地方,一切都在我的页面上运行,一旦我与 someting 交互并且它得到更新,一切正常,只是在初始化时没有
更新
这就是我的服务的样子
angular.module('servicefactories', [])
.factory('MyItemService', function ($http, $q) {
obj.getMyItem= function () {
var mypromise = $q.defer();
$http.get('getforEdit')
.success(function (data, status, headers, config) {
mypromise.resolve(data);
});
return mypromise.promise;
}
return obj;
});