imn*_*ghn 31 parent-child typescript angular
我得到类型错误,"预期0类型参数,但得到1"尽管遵循本教程到T. https://youtu.be/I317BhehZKM?t=57s
我已经指定:
newUserInfoComplete:boolean = false
Run Code Online (Sandbox Code Playgroud)
但是我<boolean>在这一行中得到了上面指定的错误:
@Output() newUserInfoCompleteEvent = new EventEmitter <boolean> ();
Run Code Online (Sandbox Code Playgroud)
此外,如果我只是省略<boolean>我得到此错误:
Argument of type 'boolean' is not assignable to parameter of type 'string'.
Run Code Online (Sandbox Code Playgroud)
和this.NewUserInfoComplete在这里加下划线:
this.newUserInfoCompleteEvent.emit(this.newUserInfoComplete);
Run Code Online (Sandbox Code Playgroud)
如果您要进行downvote,请留下关于如何改进我的问题的说明.谢谢.
这是我的组件:
import { Component, OnInit, Output } from '@angular/core';
import { slideToRight } from '../../../../router.animations';
import { Router, ActivatedRoute, UrlSegment } from '@angular/router';
import { EventEmitter } from 'protractor';
@Component({
selector: 'app-new-user-input',
templateUrl: './new-user-input.component.html',
styleUrls: ['./new-user-input.component.css'],
animations: [slideToRight()]
})
export class NewUserInputComponent implements OnInit {
newUserInfoComplete:boolean = false
@Output() newUserInfoCompleteEvent = new EventEmitter <boolean> ();
constructor(private router: Router, r: ActivatedRoute) {
r.url.subscribe((s: UrlSegment[]) => {
console.log("url", s); //https://vsavkin.com/angular-router-understanding-router-state-7b5b95a12eab
});
}
ngOnInit() {
}
sendNewUserInfoComplete(){
this.newUserInfoCompleteEvent.emit(this.newUserInfoComplete);
}
displaySibling() {
console.log(this.router);
this.router.navigate(['../', { outlets: { newuserorginfo: ['newuserorginfo'] } }])
}
closeBlade() {
this.router.navigate([{ outlets: { newuserinput: null } }]);
}
}
Run Code Online (Sandbox Code Playgroud)
Con*_*Fan 105
尝试EventEmitter从Angular 导入而不是从protractor:
import { Component, OnInit, Output, EventEmitter } from '@angular/core';
Run Code Online (Sandbox Code Playgroud)
我忘了检查我的进口!该死的。我使用的是 PROTRACTOR 的事件发射器而不是角核心事件发射器
import { EventEmitter } from '@angular/core';
import { Component, OnInit, Output } from '@angular/core';
import { slideToRight } from '../../../../router.animations';
import { Router, ActivatedRoute, UrlSegment } from '@angular/router';
@Component({
selector: 'app-new-user-input',
templateUrl: './new-user-input.component.html',
styleUrls: ['./new-user-input.component.css'],
animations: [slideToRight()]
})
export class NewUserInputComponent implements OnInit {
newUserInfoComplete = false;
@Output() newUserInfoCompleteEvent = new EventEmitter<boolean>();
constructor(private router: Router, r: ActivatedRoute) {
r.url.subscribe((s: UrlSegment[]) => {
console.log("url", s); //https://vsavkin.com/angular-router-understanding-router-state-7b5b95a12eab
});
}
ngOnInit() {
}
sendNewUserInfoComplete() {
this.newUserInfoCompleteEvent.emit(this.newUserInfoComplete);
}
displaySibling() {
console.log(this.router);
this.router.navigate(['../', { outlets: { newuserorginfo: ['newuserorginfo'] } }])
}
closeBlade() {
this.router.navigate([{ outlets: { newuserinput: null } }]);
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
你只是把导入弄错了,你需要EventEmitter从@angular/core
import { EventEmitter } from @angular/core
Run Code Online (Sandbox Code Playgroud)
小智 5
正如上面的答案中提到的,不要EventEmitter从“量角器”导入,而是从“ @angular/core ”导入。
为什么会发生这种情况:因为您在导入它EventEmmiter 之前使用了它,所以在这种情况下它会自动从“量角器”模块导入。
| 归档时间: |
|
| 查看次数: |
17784 次 |
| 最近记录: |