如何检查Angular 1.5中是否存在组件 [英] How to check if a component exists in Angular 1.5

查看:83
本文介绍了如何检查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.

跟进问题:检查是否存在Angular指令

推荐答案

在一天结束时,组件被注册为指令,因此确实需要'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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆