我在尝试运行NG Build --Prod时遇到以下错误(当然是为AoT编译)
ERROR in ng:///C:/Users/DTurcich/DashboardConsole/ASCI.DashboardConsole.Frontend/src/app/add.notification.one.dialog.component.html (7,96): Property 'newAdmin' does not exist on type 'AddNotificationOneDialog'.
ERROR in ng:///C:/Users/DTurcich/DashboardConsole/ASCI.DashboardConsole.Frontend/src/app/add.notification.one.dialog.component.html (7,138): Property 'newAdmin' does not exist on type 'AddNotificationOneDialog'.
ERROR in ng:///C:/Users/DTurcich/DashboardConsole/ASCI.DashboardConsole.Frontend/src/app/add.notification.one.dialog.component.html (13,47): Property 'newAdmin' does not exist on type 'AddNotificationOneDialog'.
ERROR in ng:///C:/Users/DTurcich/DashboardConsole/ASCI.DashboardConsole.Frontend/src/app/add.notification.one.dialog.component.html (7,4): Property 'newAdmin' does not exist on type 'AddNotificationOneDialog'.
ERROR in ng:///C:/Users/DTurcich/DashboardConsole/ASCI.DashboardConsole.Frontend/src/app/add.notification.one.dialog.component.html (6,3): Property 'newAdmin' does not exist on type 'AddNotificationOneDialog'.
尝试进行NG Build --Prod时,只会抛出这些错误。非--Prod构建正在成功完成,我知道AoT编译的方式有所不同,但我不确定我需要做些什么来纠正这种情况,因为我看起来似乎并没有帮助。 / p>
相关文件:
Angular 4打字稿:
@Component({
selector: 'add-notification-one-dialog',
templateUrl: './add.notification.one.dialog.component.html',
styleUrls: ['./dialog.component.css']
})
export class AddNotificationOneDialog {
constructor(
public dialogRef: MdDialogRef<AddNotificationOneDialog>,
private snackBar: MdSnackBar
) { }
// opens a dialog to warn the user they didn't input correctly
openSnackBar(message) {
this.snackBar.open(message, "Close", { duration: 3000 });
}
// function called on press of the submit button which checks regular expression compliance
pressSubmit(newAdmin: any): void {
var regEx = new RegExp("[^a-zA-z0-9]");
var testedInput = regEx.test(newAdmin);
if (testedInput !== true) {
this.dialogRef.close(newAdmin)
}
else {
this.openSnackBar("Please enter only A-Z and 0-9");
}
}
}
HTML:
<div class="dialog-box">
<h1 md-dialog-title>Add a new Administrator?</h1>
<md-dialog-content>
<md-input-container>
<input mdInput class="text-input" pattern="[A-Za-z0-9 ]+" placeholder="Name" maxlength="30" [(ngModel)]="newAdmin" [value]="newAdmin" (keyup.enter)="pressSubmit(newAdmin)">
</md-input-container>
</md-dialog-content>
<md-dialog-actions>
<div class="button-container">
<button class="pull-left" md-raised-button (click)="pressSubmit(newAdmin)">Submit</button>
<button class="pull-right" md-raised-button (click)="dialogRef.close('Cancel')">Cancel</button>
</div>
</md-dialog-actions>
</div>
提前谢谢!
答案 0 :(得分:2)
您忘记申报newAdmin变量:
export class AddNotificationOneDialog {
public newAdmin: any;
constructor(...){ }
...
}