角度组件:需要@Output()

时间:2019-07-11 09:11:01

标签: angular angular-components

通过设置默认值,可以在Angular组件中使用@Input()或使其为可选,但是@Output()仅是可选的。

有一种方法可以使@Output()成为必需,或者强制主机/父组件对其进行绑定?

@Component({
  selector: 'xx-foo',
  templateUrl: './foo.component.html',
  styleUrls: ['./foo.component.scss']
})
export class FooComponent {

  @Input() requiredInput: number;
  @Input() optionalInput = -1;

  @Output() optionaOutput: EventEmitter<number> = new EventEmitter<number>();
}

旁注,我使用的是Angular 8.1。

0 个答案:

没有答案
相关问题