我正在使用AngularUI Modal和AngularUI路由器進行Bootstrap。我想填充模式標題,並根據用戶點擊哪個按鈕來啓動模式,將數據添加到提交的數組中。我可以靜態添加此信息,但無法動態確定如何添加此信息。根據點擊按鈕動態添加模態信息
[編輯:添加代碼模式下面]
的JavaScript控制器:
myApp.controller('NewProjectCtrl', function ($scope, $location, $stateParams, Projects, $modalInstance) {
var editProject = this;
editProject.title = 'Modal 1'; // This title should change based on which button is clicked
editProject.save = function() {
editProject.project.type = {type: 'Basic'}; //This item should change based on which button is clicked.
$modalInstance.close(editProject.selected);
Projects.$add(editProject.project).then(function(data) {editProject.projects.$save({ type: 'Basic' }); //'Basic' should change based on which button is clicked.
});
};
editProject.cancel = function() {
$modalInstance.dismiss('cancel');
};
});
JavaScript進行模態:
.state('selection.new', {
url: '/new',
onEnter: ['$stateParams', '$state', '$modal', function ($stateParams, $state, $modal) {
$modal.open({
templateUrl: 'views/new-mark.html',
controller: 'NewProjectCtrl as editProject',
})
.result.finally(function() {
$state.go('^');
});
}]
})
HTML:
<!-- HTML for button that triggers modal 1 -->
<a ui-sref="selection.new">
<button type="button" class="btn btn-primary btn-lg" ng-click="open()">Select</button>
</a>
<!-- HTML for modal title -->
<div class="modal-header">
<h3 class="modal-title">{{editProjects.type}}</h3>
</div>
您發佈貌似控制器爲模態對話框(它注入$ modalInstance),你可以張貼代碼,您調用$ modal.open控制器?您可以在open函數中使用resolve選項來定義注入模態實例控制器的其他對象。 – 2015-03-03 01:24:58
@Brad Barber我添加了模態代碼。對不起,我應該第一次包括這一點。 – Ken 2015-03-03 01:54:27