[英]How to access a custom html element used in different .ts file from another component?
I want to access and manipulate a custom html element which is declared in another .ts file of my project from a component. 我想访问和操作一个自定义html元素,该元素在我的项目的另一个.ts文件中从一个组件声明。
/src/app/@theme/layouts/one-column/one-column-layout.ts
this is the file where the custom html element is used. /src/app/@theme/layouts/one-column/one-column-layout.ts
这是使用自定义html元素的文件。
/src/app/pages/dashboard/dashboard.component.ts
this is from where I want to access that custom element and append some innerHTML in it. /src/app/pages/dashboard/dashboard.component.ts
这是我要访问该自定义元素并在其中添加一些innerHTML的位置。
I've almost checked everything but didn't get any satisfactory answer; 我几乎检查了所有内容,但没有得到满意的答复。 what I've already checked: 我已经检查过的内容:
How to access method from .ts file into html file in angular2? 如何从angular2中的.ts文件访问HTML文件的方法?
How to access one component's state from another component 如何从另一个组件访问一个组件的状态
AngularJS 2 how to access DOM element within TS file? AngularJS 2如何访问TS文件中的DOM元素?
In one-column-layout.ts
I want to append HTML in <ng-content></ng-content>
在one-column-layout.ts
我想在<ng-content></ng-content>
附加HTML
@Component({
selector: 'ngx-one-column-layout',
styleUrls: ['./one-column.layout.scss'],
template: `
<nb-sidebar responsive right>
<nb-tabset>
<nb-tab tabIcon="person-outline" tabTitle="Customers">
<ng-content tag="right-sidebar"></ng-content>
</nb-tab>
</nb-tabset>
</nb-sidebar>
`,
})
I expect to append my html to this custom element, I know this is a rookie question though. 我希望将html附加到此自定义元素,不过我知道这是一个菜鸟问题。
If you wanna access one component from another, first of all, you should separate the template from the .ts file. 如果要从另一个组件访问一个组件,首先,应将模板与.ts文件分开。 Then you can use @ViewChild and send it to the other component with @Input / @Output depending the direction. 然后,您可以使用@ViewChild并根据方向使用@Input / @Output将其发送到其他组件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.