假设Angular 1.6应用程序使用最佳实践(组件/绑定到控制器尽可能),我们是否可以在模板中利用TypeScript的强大功能?
例如,如果我们有一些模板代码
<div>{{$ctrl.children[0].name}}</div>我们知道控制器的类型($ ctrl) - 我们可以让TypeScript给我们一个错误
$ ctrl上不存在'children' '孩子'不是一个阵列 '孩子'中的物品没有物业'名称'(等)?VS Code中的代码完成也很不错。
我见过以下问题:
https://github.com/Microsoft/TypeScript/issues/6508 https://github.com/Microsoft/TypeScript/issues/5151然而,很难从事情所在的地方得出结论(特别是在AngularJS 1.x世界中)。
Assuming an Angular 1.6 app using best practices (components/bind-to-controller where possible), can we harness the power of TypeScript in templates?
For example if we have some template code
<div>{{$ctrl.children[0].name}}</div>& we know the type of the controller ($ctrl) - can we have TypeScript give us an error if
'children' does not exist on $ctrl 'children' is not an array the items in 'children' do not have a property 'name' (etc)?Code completion in VS Code would be nice too.
I've seen the issues below:
https://github.com/Microsoft/TypeScript/issues/6508 https://github.com/Microsoft/TypeScript/issues/5151However it's difficult to conclude from that where things are at (especially in the AngularJS 1.x world).
最满意答案
没有。
AngularJs模板在运行时被解释,没有编译步骤可以进行此检查。
As an alternative you could start writing Angular 2 components and then downgrade them to AngularJS using @angular/upgrade/static::downgradeComponent downgradeComponent
更多推荐
TypeScript,$ctrl,'children',issues,Code,电脑培训,计算机培训,IT培训"/>
发布评论