Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 在ngTemplate中使用的组件内调用函数_Angular_Typescript - Fatal编程技术网

Angular 在ngTemplate中使用的组件内调用函数

Angular 在ngTemplate中使用的组件内调用函数,angular,typescript,Angular,Typescript,parent-component.component.ts @Component({ selector: 'app-parent-component', templateUrl: './parent-component.component.html', }) export class ParentComponentComponent { someFunction() { childComponent.someChildFunction() } } @Component(

parent-component.component.ts

@Component({
  selector: 'app-parent-component',
  templateUrl: './parent-component.component.html',
})
export class ParentComponentComponent {
  someFunction() {
    childComponent.someChildFunction()
  }
}
@Component({
  selector: 'app-child-component',
  templateUrl: './child-component.component.html',
})
export class ChildComponentComponent {
  someChildFunction() {
    //some usefull work
  }
}
parent-component.component.html

<ngTemplate>
  <app-child-component></app-child-component>
</ngTemplate>
<input [(ngmodel)]="search">
child-component.component.html

<ngTemplate>
  <app-child-component></app-child-component>
</ngTemplate>
<input [(ngmodel)]="search">
但是没有定义。。 然后尝试

<ng-container *ngTemplateOutlet="template"></ng-container>

在父组件中

此时,子组件内的任何更新都不会反映 就像一个输入模型


任何帮助都会有帮助。或者一些更好的解决方案也会起作用。

您需要使用@viewChild,这样您就可以从parents获取child为什么子组件包装在
中?实际上我使用的是ngx模式。。因此,组件被包装在ngTemplate中。。这不是正确的方法吗?事实上我可以解释全部事情。。也许你会有更好的主意。。我使用的是ngx引导模式,模式内容在ngx模板中引用。现在modal中的内容在很多地方被重用,所以我用它创建了一个组件。基本上,这是一种可以了解细节的形式。现在表单提交按钮处于模式级别,保存部分位于重用组件内。当我点击提交按钮时,我想点击重用组件的保存部分。任何更好的解决方案都会有所帮助