angular动态加载组件_我如何使用Angular动态组件构建可自定义的加载指示器

angular动态加载组件

Recently, I wrote a blog post about creating a reusable loading-indicator component for Angular projects. The next step is making the indicator part customizable. But how exactly do you insert your component into the overlay? That is where dynamic components can help us.

最近,我写了一篇博客文章,内容涉及为Angular项目创建可重用的加载指标组件。 下一步是使指示器零件可定制。 但是,如何精确地将组件插入叠加层? 这就是动态组件可以帮助我们的地方。

Note: Since my previous blog post, I have refactored some parts of the library. Feel free to check out the git repository.

注意: 自从上一篇博客文章以来,我已经重构了库的某些部分。 随时检查git存储库

The use-case is that we have a really easy to use loading-indicator. By default, it has a spinner, and it can be triggered using the library’s decorator methods. However, our end user wants only “Loading…” displayed on the overlay. We can copy the logic and then replace the spinner with the text itself, but that would be rather redundant.

用例是我们有一个非常易于使用的加载指示器。 默认情况下,它具有微调器,可以使用库的装饰器方法来触发它。 但是,我们的最终用户只希望在叠加层上显示“正在加载...”。 我们可以复制逻辑,然后用文本本身替换微调框,但这将是多余的。

In order to be able to use dynamic components, first, we need a simple decorator implemented. This decorator makes it possible to inject our own component into the template.

为了能够使用动态组件,首先,我们需要实现一个简单的装饰器。 这个装饰器可以将我们自己的组件注入模板。

import { Directive, ViewContainerRef } from
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值