Unf*_*ing 1 typescript angular
我有这样的父类:
export class BaseForm {
@Output() public eventSubmit:EventEmitter<any> = new EventEmitter<any>();
public emitForm() :void {
const params = this.getParams();
this.eventSubmit.emit(params);
}
public onSubmit(){
if (!this.isValid) {
return;
}
this.emitForm()
}
}
Run Code Online (Sandbox Code Playgroud)
和孩子:
@Component({
selector: 'app-auth-form',
templateUrl: './auth-form.component.html',
styleUrls: ['./auth-form.component.styl'],
})
export class AuthFormComponent extends BaseForm { }
Run Code Online (Sandbox Code Playgroud)
然后我尝试绑定另一个组件,如下所示:
<app-auth-form
(eventSubmit)="tap($event)"
[error]="error">
</app-auth-form>
Run Code Online (Sandbox Code Playgroud)
tap只是显示发出的数据.所以,然后我在BaseForm中发出一些东西,我在日志中没有任何东西.有任何想法吗?
截至2016年11月底,Angular的团队已经引入了装饰器继承.以下是您想要使用它时要记住的规则:
- 类装饰器是继承的,但从未从父类合并到子类中
- 如果子类没有定义自己的ctor,则继承ctor参数和装饰器
- 如果子类没有重新定义此方法/属性,我们将在父方法/属性上定义的装饰器继承到 - 子类
- 我们继承了生命周期方法
资料来源:https://github.com/angular/angular/issues/11606#issuecomment-261625522
方法/属性的装饰一样@Input(),@Output()和一流的装饰一样@Component(),@Directive()等等都没有继承.你必须添加
@Output() public eventSubmit:EventEmitter<any> = new EventEmitter<any>();
Run Code Online (Sandbox Code Playgroud)
也为了你的孩子班让它发挥作用.
编辑:这是一个扩展我前段时间组件的例子(popover扩展工具提示)http://plnkr.co/edit/n5jCg3sK6VRu7fZfj7i2?p=preview
| 归档时间: |
|
| 查看次数: |
4049 次 |
| 最近记录: |