Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么即使模板正在访问私有属性,Angular AOT也会编译?_Angular_Typescript_Ionic Framework_Ionic3_Angular2 Aot - Fatal编程技术网

为什么即使模板正在访问私有属性,Angular AOT也会编译?

为什么即使模板正在访问私有属性,Angular AOT也会编译?,angular,typescript,ionic-framework,ionic3,angular2-aot,Angular,Typescript,Ionic Framework,Ionic3,Angular2 Aot,首先我想说的是,我对爱奥尼亚和安格鲁是完全陌生的。请原谅我提出的任何愚蠢的问题或评论 我正在做一些测试,以更好地理解AOT编译器如何使用Angular和Ionic 我遇到过这样的情况:我有一个带有私有字段的组件,这些字段可以在我的模板中访问,但构建似乎仍然工作得很好。据我所知,这应该会产生一个错误 @IonicPage() @Component({ selector: 'page-login', templateUrl: 'login.html', }) export class LoginPa

首先我想说的是,我对爱奥尼亚和安格鲁是完全陌生的。请原谅我提出的任何愚蠢的问题或评论

我正在做一些测试,以更好地理解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>
我发现Angular github中存在一个问题,情况与此相同:

本期报道的是,只有在第二次运行ngc时才会出现错误,因为在第一次运行时,ngc生成NGFactorys,只有在第二次运行时,它才会尝试将这些工厂转换为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构建,那么这种情况可能会成为一个问题

面对这种情况:

  • 为什么我运行ionic build时AOT不报告任何错误
  • 我是否需要调整任何设置,以便ionic cli显示错误
  • 关于在模板中访问的私有字段的使用,AOT中是否有任何更改

这里有一个替代方法。即,如果安装扩展,您可以很容易地看到这些错误

关于HTML代码:

VS代码问题部分:

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'.