不知角度的用戶界面,只不過爲模態窗口的文檔始終撲朔迷離的是什麼版本。雖然你確實可以使用ngInclude指令作爲顯示模式窗口的一部分,但不需要如下所示。在下面的情況下,模態HTML和腳本在單獨的文件中,並且使用modal.open()來引用和顯示它們。出於某種原因,我只能當它被作爲$範圍的對象屬性傳遞到效果的更新模式。(參見「虛擬機。」在代碼)
ModalView.html片斷
<!-- html elements reference the ModalViewCtrl decorated $scope -->
<input ng-model='vm.email' type='email' placeholder='Email address' autofocus />
<input ng-model="vm.password" type="password" class="form-control" placeholder="Password" />
<label class="checkbox">
<input ng-model="vm.rememberMe" type="checkbox" />
Remember me
</label>
ModalViewCtrl.js片斷
angular.module('app')
.controller('ModalViewCtrl', function($scope, $modal, parms) {
/* decorate the $scope and/or preset the $scope.vm object
as needed with parms.parm1, parms.parm2, ....
*/
$scope.ok = function() {
$modalInstance.close($scope.vm);
};
$scope.cancel = function() {
$modalInstance.dismiss();
};
});
SourcePageCtrl.js片斷
angular.module('app')
.controller('SourcePageCtrl', function($scope, $modal, ...) {
$scope.open = function() {
var modalInstance = $modal.open({
templateUrl: 'path_literal_to_ModalView.html'
,controller: 'ModalViewCtrl'
,resolve : {
parms : function() { return {
parms1 : value1
,parm2 : value2
,...
}}
});
modalInstance.result.then(
function (vm) {
$scope.result = vm;
} , function() {
...
}
);
});
});
如果你想使用include,但是,有兩個陷阱。
- 的「templateUrl」必須引用調式元素的標識包含標籤,如ngInclude的ID其本身作爲反對模板文件的URL。
由於角求值屬性值,如果一個文字被提供給路徑中的元件就必須在已經引用字符串內引用的src屬性:
文檔狀態'modal'適用於已經在您的DOM中的模塊。如果DOM中尚未使用較低級別的'對話框' – charlietfl 2013-03-13 12:00:28