首先,我想说我对Ionic和Angular都是全新的。请原谅我任何愚蠢的问题或评论。
好吧,我正在做一些测试,以便更好地了解AOT编译器如何与Angular和Ionic一起使用。
我遇到过这种情况,我有一个包含私有字段的组件,可以在我的模板中访问,但构建似乎仍然完美。根据我的理解,这应该会产生错误。
@IonicPage()
@Component({
selector: 'page-login',
templateUrl: 'login.html',
})
export class LoginPage {
private username : string;
private password : string;
//etc etc
}
我的模板引用如下字段:
<ion-input [(ngModel)]="username" name="username" type="text" required>
<ion-input [(ngModel)]="password" name="password" type="password" required>
然后,我运行下面的命令并且没有出现错误:
ionic build --prod
Running app-scripts build: --prod
[22:13:51] build prod started ...
[22:13:51] clean started ...
[22:13:51] clean finished in 1 ms
[22:13:51] copy started ...
[22:13:51] deeplinks started ...
[22:13:51] deeplinks finished in 44 ms
[22:13:51] ngc started ...
[22:13:57] ngc finished in 5.39 s
[22:13:57] preprocess started ...
[22:13:57] preprocess finished in less than 1 ms
[22:13:57] webpack started ...
[22:13:57] copy finished in 5.66 s
[22:14:23] webpack finished in 25.97 s
[22:14:23] uglify started ...
[22:14:23] sass started ...
[22:14:24] sass finished in 1.35 s
[22:14:24] cleancss started ...
[22:14:25] cleancss finished in 1.22 s
[22:14:37] uglify finished in 14.13 s
[22:14:37] postprocess started ...
[22:14:37] postprocess finished in 13 ms
[22:14:37] lint started ...
[22:14:37] build prod finished in 45.69 s
我在Angular github中发现了一个问题,同样的情况:https://github.com/angular/angular/issues/14739。
此问题中报告的错误仅在第二次运行ngc时出现,因为在第一次运行中ngc生成ngfactories并且仅在第二次运行时它尝试将这些工厂转换为Javascript,然后检测到问题
marlon@marlon-dell-5480 ~/ $ node_modules/.bin/ngc
marlon@marlon-dell-5480 ~/ $ node_modules/.bin/ngc
src/pages/login/login.ngfactory.ts:234:32: Property 'username' is private and only accessible within class 'LoginPage'.
如果团队中的某个人忘记某些私人字段并以静默方式打破AOT构建,则可能会出现这种情况。
面对这种情况: