如何检查Angular 1.5中是否存在组件 [英] How to check if a component exists in Angular 1.5
问题描述
http://embed.plnkr.co/oGlcQSOM2vFcDEKP7thV/
$ injector.has('myMessageDirective')
返回true,而 $ injector.has('myMessageComponent')
不
是否有人在努力解决这个问题或有解决方案?我的担心是因为指令检查而未来的更新中可能找不到我的组件。
Is anyone struggling with this or has a solution? My "fear" is that my components might not be found in future updates because of the directive check.
推荐答案
在一天结束时,组件被注册为指令,因此确实需要'Directive'后缀。
At the end of the day, a component is registered as a directive, so 'Directive' suffix is indeed needed.
检查'has' $ injector对象的方法:
Check 'has' method of $injector object:
return {
invoke: invoke,
instantiate: instantiate,
get: getService,
annotate: createInjector.$$annotate,
has: function(name) {
return providerCache.hasOwnProperty(name + providerSuffix) || cache.hasOwnProperty(name);
}
};
您可以对其进行调试,并查看所有组件(在缓存对象内)是否已注册为指令。没有'组件'后缀。
You can debug it and see that all components (inside cache object) are registered as directives. There is no 'Component' suffix.
这篇关于如何检查Angular 1.5中是否存在组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!