Custom directive value with bindonce in Angularjs

纵饮孤独 提交于 2019-12-06 12:59:08

bo-attr doesn't actually seem like what you want to be doing, you just want a directive to evaluate and bind data without creating any watches. I made a plnkr that I think is what you want: http://plnkr.co/edit/sFPAjlRCkDuXU5UiM1U1?p=preview

app.controller('MainCtrl', function($scope) {
  $scope.name = 'World';
 });

// html
<div directive="name"></div>
// Dummy directive
app.directive('directive', function() {
  return {
    template: '<div bindonce bo-text="val"></div>',
    compile: function() {
      return {
        pre: function(scope, elt, attrs) {
          scope.val = scope.$eval(attrs.directive);
        }
      };
    }
  }
})

Woo no watches!

Let me know if I misunderstood something.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!