dem*_*mas 5 angularjs typescript
我有服务(TypeScript中的类)app/resources/GeneralResource.ts和该文件夹中的其他服务app/resources/.我想继承我的所有资源GeneralResources.
GeneralResource.ts文件按字母顺序排列的所有文件(类)都正常工作.但是之前的所有文件(类)GeneralResource.ts都有执行时错误.
这是一个示例类:
export class DefectReasonResource extends GeneralResource implements IDefectReasonResource {
static $inject = ['$q', '$http', 'baseUrl'];
constructor(public $q:ng.IQService, public $http:ng.IHttpService, public baseUrl:string) {
super($q, $http);
}
// ...
Run Code Online (Sandbox Code Playgroud)
这个类编译好:
var app;
(function (app) {
var common;
(function (common) {
var DefectReasonResource = (function (_super) {
__extends(DefectReasonResource, _super);
function DefectReasonResource($q, $http, baseUrl) {
_super.call(this, $q, $http);
this.$q = $q;
this.$http = $http;
this.baseUrl = baseUrl;
}
DefectReasonResource.$inject = ['$q', '$http', 'baseUrl'];
return DefectReasonResource;
})(common.GeneralResource);
common.DefectReasonResource = DefectReasonResource;
angular.module('myApp').service('defectReasonResource', DefectReasonResource);
})(common = app.common || (app.common = {}));
})(app || (app = {}));
Run Code Online (Sandbox Code Playgroud)
但是当我打开文件时,我在浏览器中出错:
未捕获的TypeError:无法读取undefined的属性'prototype'
我只想强调一下,我对所有后面声明的类都没有这个问题GeneralResource.
我认为删除继承并注入GeneralResource我的所有服务会更好.但我想知道有可能修复继承解决方案吗?
您没有详细说明您的设置是什么样的。但我在使用(TypeScript)内部模块时遇到了这个问题。您只需确保不要忘记添加参考注释:
///<reference path="relative/path/to/GeneralResource.ts" />
Run Code Online (Sandbox Code Playgroud)
在你的app/resources/serviceName.ts文件中。注释的目的是确保最终app.js文件中的文件顺序(或其内容)正确(如果使用--outFile标志)。
| 归档时间: |
|
| 查看次数: |
52 次 |
| 最近记录: |