简体   繁体   English

Angularjs UI Bootstrap Popover阻止输入提交

[英]Angularjs UI Bootstrap Popover Prevents input submit

I have used Angularjs with ui.bootstrap popover feature in following manner, 我已经通过以下方式将Angularjs与ui.bootstrap popover功能结合使用,

<form name="frm1" role="form" ng-submit='myFunc()' novalidate="novalidate">
  .... other inputs go here...
<input type="number" ng-pattern="/^[0-9]+$/" name="testNo" ng-model='testNo' required popover="Locate number here" popover-trigger="focus">
<input type="submit" ng-model='funcBtn' value="Submit" ng-click="submitted = true" ng-disabled="value.length=0">
</form>

The issue is because of popover="Locate number here" popover-trigger="focus" code when I check after submitting the form the value for the input testNo is not passed to controller. 问题是由于在提交表单后检查输入testNo的值未传递到控制器时,出现了popover popover="Locate number here" popover-trigger="focus"代码。

The Controller is as follows, 控制器如下,

app.controller('myCtrl', ['$scope','$location','$log', function($scope,$location,$log)
{
  $log.log('testNo', $scope.testNo);
}]);

And If I remove the popover code from this input it works fine. 而且,如果我从此输入中删除弹出代码,它将正常工作。 I like to know whether there's a specific way in using popover into inputs. 我想知道是否有将弹出框用于输入的特定方法。

Used resource ui.bootstrap example, input trigger: http://angular-ui.github.io/bootstrap/ 使用资源ui.bootstrap示例,输入触发器: http ://angular-ui.github.io/bootstrap/

The problem is that the current version of AngularJS can only have one scope for a given DOM element, and the popover creates a child scope that then gets inherited by the other directives. 问题在于,当前版本的AngularJS对于给定的DOM元素只能具有一个作用域,并且弹出框创建一个子作用域,然后该子作用域将被其他指令继承。 Fortunately, the solution is simple. 幸运的是,解决方案很简单。 Just refer to $parent. 只需参考$ parent。 my_var in the directive, in your case ng-model="$parent.$model" . 指令中的my_var ,在您的情况下为ng-model="$parent.$model"

Here is the popover FAQ on this problem. 这是有关此问题的弹出式常见问题解答

I ran into this problem in the bowels of my own custom directive, but fortunately the solution is simple there as well: rather than refer to $scope.var, refer to $scope.parent.var. 我在自己的自定义指令的开头遇到了这个问题,但幸运的是,解决方案也很简单:与其引用$ scope.var,还不如引用$ scope.parent.var。 Simple solution, but hours of debugging! 简单的解决方案,但需要数小时的调试!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM