我想在angularjs中进行输入验证。通过在无效时显示引导弹出窗口(https://angular-ui.github.io/bootstrap/#/popover)。我无法弄清楚如何触发弹出窗口。
User name:
<input type="text" name="userName" ng-model="user.name" popover="m here" popover-trigger="myForm.userName.$error.required" required>
[plunker]:http://plnkr.co/edit/PwgquZXzhacvyeKeBc2O?p=preview
答案 0 :(得分:3)
要使用自定义条件触发弹出窗口,您必须使用$ tooltipProvider
默认情况下,您只能触发弹出窗口:mouseenter,mouseleave,click,focus,blur
因此,您必须定义自定义触发器,如下所示:http://plnkr.co/edit/0wEqzz?p=preview
angular.module('myApp',['ui.bootstrap'])
.config(['$tooltipProvider', function($tooltipProvider){
$tooltipProvider.setTriggers({'customEvent': 'customEvent'});
}]);
angular.module('myApp').controller('myController', ['$scope','$timeout',
function($scope, $timeout) {
$scope.fireCustomEvent = function() {
$timeout(function() {
$('#tooltipTarget').trigger('customEvent');
}, 0);
}
}]);