javascript ngDialog $scope 变量在使用范围时不会被 $dialog 中的 ngModel 字段更新:$scope
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25716493/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ngDialog $scope variables not being updated by ngModel fields in $dialog when using scope: $scope
提问by howserss
I have a controller that creates a dialog with ngDialog.open. I assign scope:$scope and set scope variables with ng-model in the popup $dialog. However the values are not set in the controller $scope. The ng-click function is able to call a function in the $scope.
我有一个使用 ngDialog.open 创建对话框的控制器。我分配 scope:$scope 并在弹出的 $dialog 中使用 ng-model 设置范围变量。但是,这些值并未在控制器 $scope 中设置。ng-click 函数能够调用 $scope 中的函数。
Is there something I am missing, I have searched quite a bit on here and github, read the docs and worked with all the examples provided on github in the project.
有什么我遗漏的吗,我在这里和 github 上搜索了很多,阅读了文档并使用了项目中 github 上提供的所有示例。
JS Fiddles below explains. It shows that the scope:$scope is not what it seems for .open(). It is a one way binding and does not go back to $scope. .openConfrm() seems to have the expected behavior.
下面的 JS Fiddles 解释了。它表明 scope:$scope 不是 .open() 看起来的样子。这是一种单向绑定,不会回到 $scope。.openConfrm() 似乎具有预期的行为。
ngDialog.open() - http://jsfiddle.net/s1ca0h9x/(FIXED!! works like expected)
ngDialog.open() - http://jsfiddle.net/s1ca0h9x/(已修复!按预期工作)
ngDialog.openConfirm() - http://jsfiddle.net/tbosLoa9/(works as expected)
ngDialog.openConfirm() - http://jsfiddle.net/tbosLoa9/(按预期工作)
var myApplication = angular.module('myApplication', ['ngDialog']);
myApplication.controller('MainController', function ($scope, ngDialog) {
$scope.FormData={newAccountNum:''};
$scope.ShowNgDialog = function () {
ngDialog.open({
template: '<div><input type="text" ng-model="FormData.newAccountNum"/></div>',
plain: true,
scope:$scope
});
}
});
});
回答by howserss
I have edited the original post and added it below. The FIXED link shows it working and the second shows it broken. Adding a dot (using a javascript object) fixes the problem.
我已经编辑了原始帖子并在下面添加了它。FIXED 链接显示它正在工作,第二个显示它已损坏。添加一个点(使用 javascript 对象)可以解决这个问题。
ngDialog.open() - http://jsfiddle.net/s1ca0h9x/(FIXED!! works like expected)
ngDialog.open() - http://jsfiddle.net/s1ca0h9x/(已修复!按预期工作)
ngDialog.openConfirm() - http://jsfiddle.net/tbosLoa9/(works as expected)
ngDialog.openConfirm() - http://jsfiddle.net/tbosLoa9/(按预期工作)
var myApplication = angular.module('myApplication', ['ngDialog']);
myApplication.controller('MainController', function ($scope, ngDialog) {
$scope.FormData={newAccountNum:''};
$scope.ShowNgDialog = function () {
ngDialog.open({
template: '<div><input type="text" ng-model="FormData.newAccountNum"/></div>',
plain: true,
scope:$scope
});
}
});
回答by Kosmetika
ngDialog passes scope with properties of any types - http://jsfiddle.net/akgdxhd0/
ngDialog 传递具有任何类型属性的范围 - http://jsfiddle.net/akgdxhd0/
var myApplication = angular.module('myApplication', ['ngDialog']);
myApplication.controller('MainController', function ($scope, ngDialog) {
$scope.accountNum = '';
$scope.ShowNgDialog = function () {
ngDialog.open({
template: '<div><input type="text" ng-model="accountNum"/></div>',
plain: true,
scope: $scope
});
};
});