TypeScript中的AngularJS值

托比亚斯·蒂姆(Tobias Timm)

我想将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] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

TypeScript中的AngularJS值

来自分类Dev

在AngularJS中使用Typescript检查HTML中的插值/绑定

来自分类Dev

angularjs 中的插值

来自分类Dev

当注入的服务上的值更新时,如何更新AngularJS(使用TypeScript)控制器中的值

来自分类Dev

在TypeScript中限制数组的值

来自分类Dev

在<a> angularJS中获取选定的值

来自分类Dev

AngularJS中的空值错误

来自分类Dev

angularjs:从密钥对中解析值

来自分类Dev

在angularjs中获取输入值

来自分类Dev

AngularJS访问JSON中的值

来自分类Dev

在<a> angularJS中获取选定的值

来自分类Dev

AngularJS中的列值合并

来自分类Dev

AngularJS更新指令中的值

来自分类Dev

范围中的angularjs progressbar值

来自分类Dev

访问数组 AngularJS 中的值

来自分类Dev

TypeScript / angularJS HTTP GET请求中的范围

来自分类Dev

AngularJS中的TypeScript拦截器

来自分类Dev

Visual Studio在TypeScript中显示`this`的值错误

来自分类Dev

Typescript中枚举值的Symbol.iterator

来自分类Dev

在TypeScript中动态更改枚举的值

来自分类Dev

如何重置以清除Typescript类中的值

来自分类Dev

获取TypeScript中的并集元素的“值”?

来自分类Dev

在Typescript中仅包含特定值的数组

来自分类Dev

在TypeScript中扩展字典值的可能类型

来自分类Dev

TypeScript中的通用索引类型值

来自分类Dev

如何在Typescript中获取对象的值

来自分类Dev

如何使用TypeScript在CSS中更改值?

来自分类Dev

Angular / TypeScript:获取表中的值

来自分类Dev

从 JSON 解析 Typescript 中的空值映射