Angular attribute directive that wraps its element

大城市里の小女人 提交于 2019-12-06 07:17:01

What you want to do is replace:true but maintain "=ngModel"

replace:true,
scope:{
  mymodel:"=ngModel",
  editing:"=allowEdit"
}

Heres a Plunker

I hope this answers your question:
In directive options:

  1. set replace: true
  2. set transclude: "element"
  3. use ng-transclude where ever you want to put the original element within the wrapper template.

plunker link

example:

js:

var app = angular.module("test", []);

app.directive("myCustomInput", function($rootScope){
  return{
    restrict: "A",
    replace: true,
    transclude: "element",
    template: "<div class='input-wrap'>"+
    "<div ng-transclude></div>"+
    "<i class='glyphicon glyphicon-chevron-down'></i>"+
    "</div>"

  }
});

HTML:

<input my-custom-input type="text" />
Caspar Harmer

I think that using replace : true should enable you to replace the original content. Take a look at this StackOverflow answer: Here

If you had a bit more of your directive, I could have a go at getting it to work, but hopefully you can use the plnkr of the other answer to work it out.

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