我想将AngularJS值转换为TypeScript。
我该如何实现?
AngularJS
angular.module('your_app').value('cgBusyDefaults',{
message:'Loading Stuff',
backdrop: false,
templateUrl: 'my_custom_template.html',
delay: 300,
minDuration: 700,
wrapperClass: 'my-class my-class2'
});
我试图用TypeScript创建一个Class并在模块的定义中初始化该类,但是这种方法并没有成功。
打字稿
export class CgBusyDefaults {
private _message: string;
private _backdrop: boolean;
private _templateUrl: string;
private _delay: number;
private _minDuration: number;
private _wrapperClass: string;
constructor() {
this._message = 'Loading Stuff';
this._backdrop = true;
this._templateUrl = 'app/administration/partials/administration-busy.html';
this._delay = 300;
this._minDuration = 700;
this._wrapperClass = 'dv-busy';
}
get wrapperClass(): string {
return this._wrapperClass;
}
set wrapperClass(value: string) {
this._wrapperClass = value;
}
get minDuration(): number {
return this._minDuration;
}
set minDuration(value: number) {
this._minDuration = value;
}
get delay(): number {
return this._delay;
}
set delay(value: number) {
this._delay = value;
}
get templateUrl(): string {
return this._templateUrl;
}
set templateUrl(value: string) {
this._templateUrl = value;
}
get backdrop(): boolean {
return this._backdrop;
}
set backdrop(value: boolean) {
this._backdrop = value;
}
get message(): string {
return this._message;
}
set message(value: string) {
this._message = value;
}
}
angular.module('your_app').value('cgBusyDefaults', new CgBusyDefaults());
是否可以使用TypeScript定义值?也许我只是想念一些东西
使用以下TypeScript会发生什么?
export class CgBusyDefaults {
public message: string;
public backdrop: boolean;
public templateUrl: string;
public delay: number;
public minDuration: number;
public wrapperClass: string;
constructor() {
this.message = 'Loading Stuff';
this.backdrop = true;
this.templateUrl = 'app/administration/partials/administration-busy.html';
this.delay = 300;
this.minDuration = 700;
this.wrapperClass = 'dv-busy';
}
}
angular.module('your_app').value('cgBusyDefaults', new CgBusyDefaults());
使用getters&setters代替常规属性时,我遇到了一个问题。这只是预感。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句