sis*_*imh 8 angularjs ng-dialog
我在我的应用程序中使用ngDialog并且我想创建一个通用的确认模式,我可以在需要时使用它,确认消息将会有所不同.
我的问题:
1-创建一个带有ngDialog功能的指令是一个好主意,它的设计是什么?
2- ngDialog代码中confirm()和openConfirm()的区别是什么.
提前致谢
Raz*_* B. 20
好吧,回答你的问题,
1 - 你可以为它创建一个指令scope
,例如type
你传递确认类型(即submit
提交确认,delete
删除确认),指令应该根据你指定的类型呈现消息.
2 - openConfirm()
是一种ngDialog,只能通过确认动作来关闭(不像ngDialog.open()
),因此你无法在点击任何地方时关闭对话框DOM
.confirm()
您只是用于关闭对话框的方法,您可以使用此方法关闭对话框并解决打开模式时返回的承诺,以便它可以在<button ng-click="confirm()">Confirm</button>
对话框中继续.
希望这能帮到你
openConfirm()
打开一个对话框,默认情况下,在按下转义或在对话框窗口外单击时不会关闭.该函数返回一个已解决或拒绝的promise,具体取决于对话框的关闭方式.
要解决这个承诺,您的对话框应如下所示:
ngDialog.openConfirm({
template: '<div></div>',
controller: ['$scope', function($scope) {
// Controller logic here
}]
}).then(function (success) {
// Success logic here
}, function (error) {
// Error logic here
});
Run Code Online (Sandbox Code Playgroud)
ngDialog.openConfirm({
template: '<div></div>',
scope: $scope, // <- ability to use the scopes from directive controller
}).then(function (success) {
// Success logic here
}, function (error) {
// Error logic here
});
Run Code Online (Sandbox Code Playgroud)
只要scope: $scope
在对话框内部传递,就可以使用指令控制器
尝试切换类型中index.html
,从confirm
以remove
和在对话框中看到更新的内容和按钮上的文字