表达式中的赋值

时间:2013-12-13 08:47:49

标签: angularjs angularjs-directive angularjs-scope

我正在尝试制作一个接收表达式的指令作为bootstrap的'hidden.bs.modal'事件的回调:

//the use
<div class="modal" modal-on-hide="currPane = 'firstPanel'">

//the implementation
app.directive('modalOnHide', function () {
  return {
    restrict: 'A',
    link: function postLink(scope, element, attrs) {
      element.on('hidden.bs.modal', function hideCallback () {
        scope.$eval(attrs.modalOnHide);
      });
    }
  };
});

currPane是父作用域上的attr,它与指令的作用域相同,但是当hideCallback执行时,它没有被设置为新值。想法?

1 个答案:

答案 0 :(得分:1)

尝试这种方式:

element.on('hidden.bs.modal', function hideCallback () {
    scope.$apply(function(){
        scope.$eval(attrs.modalOnHide);
    });
});

或者:

element.on('hidden.bs.modal', function hideCallback () {
    scope.$apply(attrs.modalOnHide);
});