changing a controller scope variable in a directive is not reflected in controller function

前端 未结 4 492
傲寒
傲寒 2020-12-16 08:11

In my directive, I have a controller variable, page which gets incremented when you press the button in the directive. However, the next line, scope.alertPage()

4条回答
  •  难免孤独
    2020-12-16 08:58

    You can pass the variable by reference, then the update will be immediate (because you wont copy it, but simply pass its location in memory).

    View:

    
    

    Directive:

    link: function(scope, elem, attrs) {
      scope.incrementPage = function() {
          scope.page.page += 1;
          scope.alertPage();
      }
    

提交回复
热议问题