AngularJS Directive is not linking when using an input in the template to replace an input in the html with the type attribute specified

大兔子大兔子 提交于 2019-12-04 14:56:34

One thing jumped out at me: your directive is doing replace. The markup of the template you are replacing it with does not have the type="text", whereas the original markup does. I have noticed that replace does a sort of merge, and it may be getting confused when trying to merge or replace some HTML that has an attribute with a template that does not.

Interestingly, you don't really need to replace the original markup with a template at all. That is one use of directives, but not the most powerful in my opinion. Take "replace" off and remove the template entirely, if you're just trying to extend the typeahead anyway. In my own projects, for example, I might put several different directives attributes on a single element and they all add their own flavor of extra functionality to the existing element. All of them have a reference to the same $element, you just have to be careful that they don't conflict.

I wrote the rest of this before I looked at the fiddle first, sorry.

I'm on a chromebook so I can't test the IE8 thing, but if I recall IE is very picky about HTML attributes. Have you tried any of the following:

  • Alternate directive specification, as in data-search-directive
  • Make sure the directive has a property, as in search-directive="", even if you don't use it
  • Is the template cache really necessary? Have you tried this just by putting the template in a template property of the directive?
  • Is IE8 happy without "use strict"?
  • Have you seen the angular ui bootstrap alternative typeahead? At the very least, looking at what they did may give you ideas of how to do what you are trying to do.
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!