angular input formatter/parser directive and interpolated attributes?

*爱你&永不变心* 提交于 2019-12-07 08:40:27

When you add the isolate scope, you're creating brand-new child scope that doesn't inherit from the scope with the ngModel's value in it. That's why your parsers and formatters are getting undefined.

Also, in your example, to get at the value of bar, you don't need it in curly braces:

<input ng-model='foo' my-directive='bar' />

And in your linking function:

link: function(scope, element, attr, ctrl) {
  attr.myDirective == 'bar'.
  scope.$eval(attr.myDirective) == // whatever the value of 'bar' is in the current scope
}

So you don't need the isolate scope. Just use scope.$eval to evaluate the expression passed to your directive.

Here's a quick fiddle.

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