我有兩個功能,我想調用一個功能,其他只有第一個功能解決成功。如何解決功能和角度調用其他功能
$scope.createNewWorkModule = function (data, selectedUser) {
$scope.workOrderInfo = $localStorage.workOrderInfo;
$scope.createNewWorkOrder($scope.workOrderInfo).then(function (response) {
$scope.workOrderId = $localStorage.workOrderId;
var newWM = {
name: data.name,
};
$scope.myPromise = operationsFactory.createWorkModule(angular.toJson(newWM)).success(function (response) {
$rootScope.workModules = response.result;
return $scope.workOrder;
})
});
};
$scope.createNewWorkOrder = function (data) {
var newWD = {
name: data.name,
description: data.description,
user_id: $cookies.userId
};
$scope.myPromise = operationsFactory.createWorkOrder(angular.toJson(newWD)).success(function (response) {
$localStorage.workOrderId = response.result.id;
})
return $localStorage.workOrderId;
};
我想打電話給$scope.createNewWorkOrder
與.then
,但它給錯誤
TypeError: Cannot read property 'then' of undefined at Scope.$scope.createNewWorkModule (work-order-create-controller.js:36) at $parseFunctionCall (angular.js:12158)
。
我該如何解決這個問題?
更新:
無法更新與檢索的數據視圖:
<div class="panel panel-default">
<div class="panel-heading font-bold">
<span>List of Work Modules</span>
</div>
<ul ng-repeat="wm in workModules" style="list-style: none">
<li>{{wm.name}}</li>
<li>{{wm.description}}</li>
</ul>
</div>
非常感謝鄧肯。一個問題是我無法更新視圖模型數據(workModules),即使它在根範圍內 – Satyadev