Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJS-在按钮上关闭引导popover从popover内单击_Angularjs_Twitter Bootstrap 3 - Fatal编程技术网

AngularJS-在按钮上关闭引导popover从popover内单击

AngularJS-在按钮上关闭引导popover从popover内单击,angularjs,twitter-bootstrap-3,Angularjs,Twitter Bootstrap 3,正如通过plunker演示的那样。我想在单击取消按钮时显示一个引导弹出窗口。当我第一次点击按钮时,它会打开popover,但之后我必须点击两次按钮才能打开popover。有什么想法吗?我可能有一个解决办法: elem.popover({ html: true, content: $compile(content)(scope), placement: 'top', trigger: 'manual' }); elem.on('click', function() {

正如通过plunker演示的那样。我想在单击
取消
按钮时显示一个引导弹出窗口。当我第一次点击按钮时,它会打开popover,但之后我必须点击两次按钮才能打开popover。有什么想法吗?

我可能有一个解决办法:

elem.popover({
   html: true,
   content: $compile(content)(scope),
   placement: 'top',
   trigger: 'manual'
});

elem.on('click', function() {
   elem.popover('show');
});

这样,如果显示了popover,就必须手动触发,并在元素上添加click侦听器

我可能有一个解决办法:

elem.popover({
   html: true,
   content: $compile(content)(scope),
   placement: 'top',
   trigger: 'manual'
});

elem.on('click', function() {
   elem.popover('show');
});

这样,如果显示了popover,就必须手动触发,并在元素上添加click侦听器

我可能有一个解决办法:

elem.popover({
   html: true,
   content: $compile(content)(scope),
   placement: 'top',
   trigger: 'manual'
});

elem.on('click', function() {
   elem.popover('show');
});

这样,如果显示了popover,就必须手动触发,并在元素上添加click侦听器

我可能有一个解决办法:

elem.popover({
   html: true,
   content: $compile(content)(scope),
   placement: 'top',
   trigger: 'manual'
});

elem.on('click', function() {
   elem.popover('show');
});
这样,如果显示了popover,就必须手动触发,并在元素上添加click侦听器

为您查看解决方案

获取此信息的步骤:

1.从脚本中删除指令

2.从添加bootstrap-tpls.js并将其包含在页面标题中

3.将脚本更改为具有注入引导和控制器的应用程序:

var app = angular.module('myApp', ['ui.bootstrap']);

app.controller('AppController', function($scope) {
  $scope.yes = function() {
      console.log('yes called');
    };

    $scope.no = function() {
      console.log('no called');
    };
});
4.使用以下标记创建
yes-no.html
模板:

 <div><button id="yes" class="btn btn-default" ng-click="no()">No</button>&nbsp;
 <button id="no" class="btn btn-primary" ng-click="yes()">Yes</button></div>&nbsp;
否
对
5.将“取消”按钮更改为

 <button popover-trigger="focus" uib-popover-template="'yes-no.html'" popover-title="Some title here?" type="button" class="btn btn-danger">Cancel</button>
取消
享受一个简单得多的解决方案。

看看适合您的解决方案

获取此信息的步骤:

1.从脚本中删除指令

2.从添加bootstrap-tpls.js并将其包含在页面标题中

3.将脚本更改为具有注入引导和控制器的应用程序:

var app = angular.module('myApp', ['ui.bootstrap']);

app.controller('AppController', function($scope) {
  $scope.yes = function() {
      console.log('yes called');
    };

    $scope.no = function() {
      console.log('no called');
    };
});
4.使用以下标记创建
yes-no.html
模板:

 <div><button id="yes" class="btn btn-default" ng-click="no()">No</button>&nbsp;
 <button id="no" class="btn btn-primary" ng-click="yes()">Yes</button></div>&nbsp;
否
对
5.将“取消”按钮更改为

 <button popover-trigger="focus" uib-popover-template="'yes-no.html'" popover-title="Some title here?" type="button" class="btn btn-danger">Cancel</button>
取消
享受一个简单得多的解决方案。

看看适合您的解决方案

获取此信息的步骤:

1.从脚本中删除指令

2.从添加bootstrap-tpls.js并将其包含在页面标题中

3.将脚本更改为具有注入引导和控制器的应用程序:

var app = angular.module('myApp', ['ui.bootstrap']);

app.controller('AppController', function($scope) {
  $scope.yes = function() {
      console.log('yes called');
    };

    $scope.no = function() {
      console.log('no called');
    };
});
4.使用以下标记创建
yes-no.html
模板:

 <div><button id="yes" class="btn btn-default" ng-click="no()">No</button>&nbsp;
 <button id="no" class="btn btn-primary" ng-click="yes()">Yes</button></div>&nbsp;
否
对
5.将“取消”按钮更改为

 <button popover-trigger="focus" uib-popover-template="'yes-no.html'" popover-title="Some title here?" type="button" class="btn btn-danger">Cancel</button>
取消
享受一个简单得多的解决方案。

看看适合您的解决方案

获取此信息的步骤:

1.从脚本中删除指令

2.从添加bootstrap-tpls.js并将其包含在页面标题中

3.将脚本更改为具有注入引导和控制器的应用程序:

var app = angular.module('myApp', ['ui.bootstrap']);

app.controller('AppController', function($scope) {
  $scope.yes = function() {
      console.log('yes called');
    };

    $scope.no = function() {
      console.log('no called');
    };
});
4.使用以下标记创建
yes-no.html
模板:

 <div><button id="yes" class="btn btn-default" ng-click="no()">No</button>&nbsp;
 <button id="no" class="btn btn-primary" ng-click="yes()">Yes</button></div>&nbsp;
否
对
5.将“取消”按钮更改为

 <button popover-trigger="focus" uib-popover-template="'yes-no.html'" popover-title="Some title here?" type="button" class="btn btn-danger">Cancel</button>
取消

享受更简单的解决方案。

代码中的问题是由于popover具有切换功能。因此,在关闭popover后,第一次单击它时,实际上它会删除切换,第二次已经打开了popover

解决方案(基于您的PRUNKR):

将控制器和指令更改为上述内容:

app.controller('AppController', function($scope) {
 $scope.cancel = function(msg) {
  $scope.msg = msg;
 };
});

app.directive('cancelConfirmation', function($compile, $timeout) {
return {
  restrict: 'A',
  scope: {
    onCancel: '&'
  },
  link: function(scope, elem, attrs) {

      var content = '<div><p>Are you sure you want to cancel?</p><button id="yes" class="btn btn-default" ng-click="no()">No</button>&nbsp;' +
        '<button id="no" class="btn btn-primary" ng-click="yes()">Yes</button></div>&nbsp;';

      elem.popover({
        html: true,
        content: $compile(content)(scope),
        placement: 'top'
      });

      elem.on('shown.bs.popover', function() {
        elem.attr('disabled', true);
      });

      scope.yes = function() {
        elem.popover('hide');
        elem.triggerHandler('click');
        elem.attr('disabled', false);
        scope.onCancel()('yes called');
      };

      scope.no = function() {
        elem.popover('hide');
        elem.triggerHandler('click');
        elem.attr('disabled', false);
      };
  }
};
});
app.controller('AppController',函数($scope){
$scope.cancel=函数(msg){
$scope.msg=msg;
};
});
app.directive('cancelConfirmation',函数($compile,$timeout){
返回{
限制:“A”,
范围:{
onCancel:“&”
},
链接:功能(范围、要素、属性){
var content='确定要取消吗?

否+ “是的”; 波弗({ 是的, 内容:$编译(内容)(范围), 位置:'顶部' }); elem.on('show.bs.popover',function(){ 要素属性(“禁用”,真); }); scope.yes=函数(){ popover元素(“隐藏”); 元素triggerHandler('click'); 要素属性(“已禁用”,错误); scope.onCancel()('yescalled'); }; scope.no=函数(){ popover元素(“隐藏”); 元素triggerHandler('click'); 要素属性(“已禁用”,错误); }; } }; });
在“取消”按钮上:

<button class="btn btn-danger" cancel-confirmation data-on-cancel="cancel">Cancel</button>
取消

代码中的问题是由于popover具有切换功能。因此,在关闭popover后,第一次单击它时,实际上它会删除切换,第二次已经打开了popover

解决方案(基于您的PRUNKR):

将控制器和指令更改为上述内容:

app.controller('AppController', function($scope) {
 $scope.cancel = function(msg) {
  $scope.msg = msg;
 };
});

app.directive('cancelConfirmation', function($compile, $timeout) {
return {
  restrict: 'A',
  scope: {
    onCancel: '&'
  },
  link: function(scope, elem, attrs) {

      var content = '<div><p>Are you sure you want to cancel?</p><button id="yes" class="btn btn-default" ng-click="no()">No</button>&nbsp;' +
        '<button id="no" class="btn btn-primary" ng-click="yes()">Yes</button></div>&nbsp;';

      elem.popover({
        html: true,
        content: $compile(content)(scope),
        placement: 'top'
      });

      elem.on('shown.bs.popover', function() {
        elem.attr('disabled', true);
      });

      scope.yes = function() {
        elem.popover('hide');
        elem.triggerHandler('click');
        elem.attr('disabled', false);
        scope.onCancel()('yes called');
      };

      scope.no = function() {
        elem.popover('hide');
        elem.triggerHandler('click');
        elem.attr('disabled', false);
      };
  }
};
});
app.controller('AppController',函数($scope){
$scope.cancel=函数(msg){
$scope.msg=msg;
};
});
app.directive('cancelConfirmation',函数($compile,$timeout){
返回{
限制:“A”,
范围:{
onCancel:“&”
},
链接:功能(范围、要素、属性){
var content='确定要取消吗?

否+ “是的”; 波弗({ 是的, 内容:$编译(内容)(范围), 位置:'顶部' }); elem.on('show.bs.popover',function(){ 要素属性(“禁用”,真); }); scope.yes=函数(){ popover元素(“隐藏”); 元素triggerHandler('click'); 要素属性(“已禁用”,错误); scope.onCancel()('yescalled'); }; scope.no=函数(){ popover元素(“隐藏”); 元素triggerHandler('click'); 要素属性(“已禁用”,错误); }; } }; });
在“取消”按钮上:

<button class="btn btn-danger" cancel-confirmation data-on-cancel="cancel">Cancel</button>
取消

代码中的问题是由于popover具有切换功能。因此,在关闭popover后,第一次单击它时,实际上它会删除切换,第二次已经打开了popover

解决方案(基于您的PRUNKR):

将控制器和指令更改为上述内容:

app.controller('AppController', function($scope) {
 $scope.cancel = function(msg) {
  $scope.msg = msg;
 };
});

app.directive('cancelConfirmation', function($compile, $timeout) {
return {
  restrict: 'A',
  scope: {
    onCancel: '&'
  },
  link: function(scope, elem, attrs) {

      var content = '<div><p>Are you sure you want to cancel?</p><button id="yes" class="btn btn-default" ng-click="no()">No</button>&nbsp;' +
        '<button id="no" class="btn btn-primary" ng-click="yes()">Yes</button></div>&nbsp;';

      elem.popover({
        html: true,
        content: $compile(content)(scope),
        placement: 'top'
      });

      elem.on('shown.bs.popover', function() {
        elem.attr('disabled', true);
      });

      scope.yes = function() {
        elem.popover('hide');
        elem.triggerHandler('click');
        elem.attr('disabled', false);
        scope.onCancel()('yes called');
      };

      scope.no = function() {
        elem.popover('hide');
        elem.triggerHandler('click');
        elem.attr('disabled', false);
      };
  }
};
});
app.controller('AppController',函数($scope){
$scope.cancel=函数(msg){
$scope.msg=msg;
};
});
app.directive('cancelConfirmation',函数($compile,$timeout){
返回{
限制:“A”,
范围:{
onCancel:“&”
},
链接: