I have 2 components. The first app-aaa
hasapp-bbb
inside.
aaa-component.html:
<button (click)="clickMe(flight)" type="submit">click me</button>
<app-bbb [flight]="flight"></app-bbb>
aaa-component.ts:
export class AaaComponent implements OnInit {
@ViewChild(BbbComponent) change: BbbComponent;
constructor(){}
ngOnInit() {
flight: ModelFlights = {
name:''
value:''
}
}
clickMe(form) {
this.change.change();
}
}
bbb-component.ts:
export class BbbComponent implements OnInit {
@Input() flight: ModelFlights;
constructor(private cdRef: ChangeDetectorRef, private sanitizer: DomSanitizer, private renderer2: Renderer2,
@Inject(DOCUMENT) private _document) {}
ngOnInit(){}
change() {
console.log('change event ');
// ...
}
}
I want to make access to the method from the bbb-component
component by clicking the clickMe
button
currently receiving error message:
ERROR TypeError: Cannot read property change
of undefined
at AaaComponent.push../src/app/core/aaa/aaa.component.ts.AaaComponent.clickMe
line: this.change.change();
I have such libraries:
{
"name": "weco-travel-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"scss": "node-sass --watch assets/scss -o assets/css"
},
"private": true,
"dependencies": {
"@angular/animations": "^7.2.15",
"@angular/cdk": "^7.3.7",
"@angular/common": "~7.2.0",
"@angular/compiler": "~7.2.0",
"@angular/core": "~7.2.0",
"@angular/forms": "~7.2.0",
"@angular/material": "^7.3.7",
"@angular/material-moment-adapter": "^8.0.2",
"@angular/platform-browser": "~7.2.0",
"@angular/platform-browser-dynamic": "~7.2.0",
"@angular/router": "~7.2.0",
"@angular/service-worker": "^8.0.0",
"animate": "^1.0.0",
"bootstrap": "^4.3.1",
"core-js": "^2.5.4",
"font-awesome": "^4.7.0",
"hammerjs": "^2.0.8",
"jquery": "^3.4.1",
"moment": "^2.24.0",
"ng-connection-service": "^1.0.4",
"ng-recaptcha": "^4.3.0",
"ngx-owl-carousel": "2.0.5",
"node-sass": "^4.12.0",
"popper.js": "^1.15.0",
"resize-observer-polyfill": "^1.5.1",
"rxjs": "~6.3.3",
"tslib": "^1.9.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.13.0",
"@angular/cli": "~7.3.9",
"@angular/compiler-cli": "~7.2.0",
"@angular/language-service": "~7.2.0",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.5.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~4.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~3.2.2",
"webpack": "^4.32.1",
"webpack-dev-server": "^3.4.1"
},
"description": "This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 7.3.9.",
"main": "index.js",
"author": "",
"license": "ISC"
}
Please help