我在AngularJS上構建應用程序,我正在使用UI模式,但不是爲編輯和創建創建單獨視圖(這是相同的)我希望兩個實例運行在同一模式視圖。這是我做過什麼AngularJS用戶界面模式無法正常工作
我有這對於創建和編輯功能中的一個主控制器,兩人打開自己的模式的實例:
(function()
{
'use strict';
angular.module('app.projects')
.controller('ProjectsController', ProjectsController);
ProjectsController.$inject = ['$scope', '$modal'];
function ProjectsController($scope, $modal)
{
$scope.edit = function(projectId)
{
var modalInstance = $modal.open(
{
templateUrl: 'modules/projects/view/modal/project.html',
controller: 'EditProjectModalInstController',
size: 'lg',
resolve: {
projectId: function(){
return projectId;
}
}
});
};
$scope.create = function()
{
var modalInstance = $modal.open(
{
templateUrl: 'modules/projects/view/modal/project.html',
controller: 'CreateProjectModalInstController',
size: 'lg',
});
};
};
})();
這裏有那些模式的情況下,控制器: EditProjectModalInstanceController
(function()
{
'use strict';
angular.module('app.projects')
.controller('EditProjectModalInstController', EditProjectModalInstController);
EditProjectModalInstController.$inject = ['ProjectsService', '$scope', '$modalInstance', 'projectId'];
function EditProjectModalInstController(projectsService, $scope, $modalInstance, projectId)
{
$scope.project = function(){return projectsService.project;};
$scope.statuses = [
{name: 'Active', value: 0},
{name: 'Finished', value: 1}
];
$scope.cancel = function() {};
$scope.save = function(){};
};
})();
,這裏是CreateProjectModalInstanceController.js
(function()
{
'use strict';
angular.module('app.projects')
.controller('CreateProjectModalInstController', CreateProjectModalInstController);
CreateProjectModalInstController.$inject = ['ProjectsService', '$scope', '$modalInstance'];
function CreateProjectModalInstController(projectsService, $scope, $modalInstance)
{
$scope.project = function(){return {};};
$scope.statuses = [
{name: 'Active', value: 0},
{name: 'Finished', value: 1}
];
$scope.cancel = function(){};
$scope.save = function(){};
};
})();
因此,每個實例控制器具有相同的功能,只是他們應該做不同的事情取決於行動(編輯或創建)。
這裏是實際的模板: project.html
<div class="modal-body">
<form class="form-horizontal">
<div class="form-group">
<label for="inputName" class="control-label col-xs-2">Name</label>
<div class="col-xs-10">
<input type="text" class="form-control" id="inputName" placeholder="Name" ng-model="project().name">
</div>
</div>
<div class="form-group">
<label for="inputName" class="control-label col-xs-2">Status</label>
<div class="col-xs-10">
<select class="form-control" ng-model="project().status">
<option ng-repeat="status in statuses" value="{{status.value}}">{{status.name}}</option>
</select>
</div>
</div>
</form>
</div>
<div class="modal-footer">
<button ng-click="save()"> Save </button>
<button ng-click="cancel()">Cancel</button>
</div>
最後的問題,在這裏我的問題是,編輯功能工作正常,但在創建模式打開時,我可以不編輯字段。我擔心我在這裏做錯了什麼,從設計主管的角度來看,如果有更多經驗的人能指出正確的做法,我會非常感激。