Angularjs的PHPStorm/WebStorm中的代码高亮显示
在我的控制器中,我有一个函数定义为:Angularjs的PHPStorm/WebStorm中的代码高亮显示,angularjs,phpstorm,webstorm,Angularjs,Phpstorm,Webstorm,在我的控制器中,我有一个函数定义为: var ProductListingHeaderController = function (FilterService, CategoryService) { this.isCategorySet = function () { return (FilterService.categoryID); }; this.categoryName = function () { return (Categor
var ProductListingHeaderController = function (FilterService, CategoryService) {
this.isCategorySet = function () {
return (FilterService.categoryID);
};
this.categoryName = function () {
return (CategoryService.categoryName());
};
};
IDE通过代码高亮显示将categoryName报告为正在使用,而将CategorySet报告为未使用
这是可以理解的,因为:
categoryName在html文件的{{}内使用:
<h2>{{productListingHeader.categoryName()}}</h2>
考虑到这是一种常见的用法,我怀疑我可能在Storm中缺少了一个设置,即如何设置东西,以便Angle指令在字符串中的这种用法在使用时得到识别
提前感谢您的反馈。这是PHP/WebStorm的正常行为 模板->JavaScript实际上只是一个模棱两可的连接。AngularJS模板中不支持jsDoc类型推断。因此,只要函数名是唯一的,PHP/WebStorm将匹配JavaScript的模板函数调用 PHP/WebStorm在将闭包方法推断为对象函数时存在问题。我在使用AngularJS控制器的原型声明时取得了更好的成功
var ProductListingHeaderController = function (FilterService, CategoryService) {
this.filterService = FilterService;
this.categoryService = CategoryService;
}
ProductListingHeaderController.prototype.isCategorySet = function () {
return (this.filterService.categoryID);
};
ProductListingHeaderController.prototype.categoryName = function () {
return (this.categoryService.categoryName());
};
将上面的代码与您的代码进行比较,并查看WebStorm中的explore结构。当您为控制器使用原型时,它们会正确地显示在资源管理器中
var ProductListingHeaderController = function (FilterService, CategoryService) {
this.filterService = FilterService;
this.categoryService = CategoryService;
}
ProductListingHeaderController.prototype.isCategorySet = function () {
return (this.filterService.categoryID);
};
ProductListingHeaderController.prototype.categoryName = function () {
return (this.categoryService.categoryName());
};