角访问ngModel控制器指令在编译自定义模板

角访问ngModel控制器指令在编译自定义模板

本文介绍了角访问ngModel控制器指令在编译自定义模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要访问的ngModel控制器(以备后用setValidity验证自定义输入字段)。然而,当我想用​​该指令作为一个属性(而非类),则replaceWith函数抛出一个错误,它无法找到ngModel控制器。我创建了一个小提琴这里:

jsfiddle.net/6HcGS/396

任何人能帮助我吗?

这是有关我的第一个问题:

databinding定制指令角度与编译功能替换HTML


解决方案

 <输入比比NG模型=称号>

比比和ngModel都是指令被呈现在一个特定的顺序。在这种情况下,比比被ngModel之前渲染。您可以重新排列像马克西姆Shoustin指令建议,或者你可以通过提供上像这样的指令创建功能优先属性指定渲染顺序:

  .directive(活泼,函数($编译){
    返回{
      限制:'A',
      优先级:-1,
      更换:真实,
      ...

默认preority是0指令具有更高的优先级第一渲染。

I want to access the ngModel controller (to later use setValidity to validate the custom input field). However, when I want to use the directive as an attribute (not class), the replaceWith function throws an error that It can not find ngModel controller. I created a fiddle here:

jsfiddle.net/6HcGS/396

Can anybody help me out?

This is related to my first questions:

databinding custom directive angular with replacing html in compile function

解决方案
<input zippy ng-model="title">

zippy and ngModel are both directives that are render in a specific order. In this case zippy gets rendered before ngModel. You can reorder the directives like Maxim Shoustin suggested or you could specify the rendering order by providing a priority attribute on the directive creation function like so:

  .directive('zippy', function($compile){
    return {
      restrict: 'A',
      priority: -1,
      replace: true,
      ...

The default preority is 0. Directives with higher priorities are rendered first.

这篇关于角访问ngModel控制器指令在编译自定义模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 01:26