我尝试通过'Alert'按钮点击调用函数testAlert()。
组件代码:
import { Component, Input, OnInit } from '@angular/core';
import { Router } from "@angular/router";
import { Radio } from './radio.model';
import { RadioService } from './radio.service';
import '/app/rxjs-extensions';
@Component({
moduleId: module.id,
selector: 'radio',
templateUrl: 'radio.component.html',
styleUrls: [ 'radio.component.css' ]
})
export class RadioComponent implements OnInit {
@Input() radio: Radio;
errorMessage: String;
constructor(
private radioService: RadioService,
private router: Router
) { }
testAlert() {
console.log("Hi!");
}
ngOnInit(): void {
this.getRadio();
}
getRadio() {
this.radioService.getRadio()
.then(
radio => this.radio = radio,
error => this.errorMessage = <any>error);
}
/*
* Sent Radio setting to Dropwizard server and then to C server
*/
save(): void {
this.radioService.updateRadio(this.radio)
.then(() => this.goBack());
}
/*
* Sent Radio setting to Dropwizard Rest Container
*/
saveRest(): void {
this.radioService.updateRadio(this.radio)
.then(() => this.goBack());
}
goBack(): void {
this.router.navigate(['/home']);
}
}
查看代码:
<div *ngIf="radio">
<div>
<label>Frequency, GHz: </label>
<input [(ngModel)]="radio.freq" placeholder="freq"/>
</div>
<div>
<label>TX Power, dBm: </label>
<input [(ngModel)]="radio.power" placeholder="power"/>
</div>
<div>
<label>RSSI, dBm: </label>
<input [(ngModel)]="radio.rssi" placeholder="rssi" readonly/>
</div>
<div>
<label>Type: </label>
<input [(ngModel)]="radio.type" placeholder="type"/>
</div>
<button (click)="save()">Apply</button>
<button (click)="saveRest()">Ok</button>
<button (click)="goBack()">Back</button>
</div>
<div>
<button (click)="testAlert()">Alert</button>
</div>
当我点击“提醒”按钮时,我收到以下错误:
“EXCEPTION:错误 http://localhost:9090/app/radio/radio.component.html:22:2引起的: self.context.testAlert不是函数“core.umd.js:3491:13错误: http://localhost:9090/app/radio/radio.component.html:22:2中的错误 由以下原因引起:self.context.testAlert不是函数(未知) 原始异常:self.context.testAlert不是函数 core.umd.js:3493:17 ORIGINAL STACKTRACE:core.umd.js:3496:17 anonymous/View_RadioComponent0.prototype.handleEvent_4@/AppModule/RadioComponent/component.ngfactory.js:80:21 DebugAppViewhttp://本地主机:9090/node_modules/@angular/core/bundles/core.umd.js:12783:28 decoratePreventDefault /&LT; @ http://localhost:9090/node_modules/@angular/platform-browser/bundles/platform-browser.umd.js:3223:55 ZoneDelegate.prototype.invokeTask@http://localhost:9090/node_modules/zone.js/dist/zone.js:275:21 NgZonehttp://本地主机:9090/node_modules/@angular/core/bundles/core.umd.js:4401:32 ZoneDelegate.prototype.invokeTask@http://localhost:9090/node_modules/zone.js/dist/zone.js:274:21 Zone.prototype.runTask@http://localhost:9090/node_modules/zone.js/dist/zone.js:151:28 ZoneTask/this.invoke@http://localhost:9090/node_modules/zone.js/dist/zone.js:345:28 core.umd.js:3497:17错误上下文:core.umd.js:3500:17对象{ _view:Object,_nodeIndex:4,_tplRow:22,_tplCol:2}
我尝试将方法'save()'的名称更改为'save1()'。没有改变。调用'save()'方法的按钮工作正常。在我对代码进行一些更改后,似乎我的项目代码没有改变。
它有什么用?