簡體   English   中英

文本輸入到AngularJS中的變量

[英]text input to variable in AngularJS

我想將以兩個文本輸入形式編寫的數據保存到變量中。

這是我的rtmNav.html

<div class="rtm-nav">
<label>From:
        <input type="text" name="input" ng-model="ctrl.dataa.from">
    </label>
    <label>To:
        <input type="text" name="input" ng-model="ctrl.dataa.to">
    </label>
</div>

這是已經存在的控制器。 我無法更改它的結構,而且與經典版本相比,它看起來也有所不同。 我必須在這里添加變量:

demand.js

class DemandCtrl {
    constructor(ChartDataService) {
        this.ChartDataService = ChartDataService;
    }

    $onInit() {
        getData.call(null, this);       
    }
    /////////////// THIS IS WHERE I GUESS I SHOULD ADD THE VARIABLES
    this.dataa = {
        from: '',
        to: ''
    };
    ////////////
}

... other methods ...

export const Demand = {
    bindings: {
        data: '<'
    },
    templateUrl: demandPageHtml,
    controller: DemandCtrl
};

可能不是將其添加到此處的正確方法,因為我從代碼編輯器收到以下消息:

[js]意外令牌。 預期使用構造函數,方法,訪問器或屬性。

任何想法如何解決這個問題?

將變量聲明放入constructor

class DemandCtrl {

    constructor(ChartDataService) {
        this.ChartDataService = ChartDataService;
        this.dataa = {
            from: '',
            to: ''
        };
    }

    $onInit() {
        getData.call(null, this);       
    }

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM