加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angular – 将数据从html主体传递到根组件

发布时间:2020-12-17 17:50:53 所属栏目:安全 来源:网络整理
导读:我一直在尝试将数据从主布局index.html文件传递到角度根/起始组件 my-app.很遗憾,我无法像这样传递它们: my-app [bodyData] =“'传递'” / my-app来自我的index.html. 任何人都可以帮助我如何通过它们?提供了测试链接. Plunker Test App Link 解决方法 属
我一直在尝试将数据从主布局index.html文件传递到角度根/起始组件< my-app>.很遗憾,我无法像这样传递它们:< my-app [bodyData] =“'传递'”>< / my-app>来自我的index.html.

任何人都可以帮助我如何通过它们?提供了测试链接.

Plunker Test App Link

解决方法

属性绑定不适用于根组件,即您引导的组件.

The reason why this is not working is that your index.html in which you place the is not an angular component. Because of this,Angular won’t compile this element. And Angular does not read attribute values during runtime,only during compile time,as otherwise,we would get a performance hit. (Tobias Bosch)

看到这个问题:

> Angular 2 input parameters on root directive

解决方法是利用DOM:

<my-app bodyData="passed" ></my-app>

在组件中:

@Component({
  selector: 'my-app',template: `
    (...)
  `
})
export class MyAppComponent {
  constructor(private eltRef:ElementRef) {
    let prop = eltRef.getAttribute('bodyData');
  }
}

这只适用于字符串属性……

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读