AngularJS中復選框(checkbox)的ng-model


ng-model 是 AngularJS 中的一個重要屬性,表示數據的雙向綁定。
但是當其作用在復選框中時,與其他可輸入文本的表單又稍有區別。

復選框中的 ng-model ,其值只有 truefalse
不用想,就知道代表的是『是否選中』的意思。

比如,頁面初始化時,我在controller中定義如下:

$scope.plan = {
    lastYear:false,
    custom:true
};

而頁面方面:

<div class="col-md-12">
    <div class="form-inline">
        <input type="checkbox" id="lastYear" ng-model="plan.lastYear" ng-click="clickLastYear()">
        <label for="lastYear" ng-click="clickLastYear()">根據上一年xxx生成公區預算明細</label>
    </div>
    <div class="form-inline">
        <input type="checkbox" id="custom" ng-model="plan.custom" ng-click="clickContent()">
        <label for="custom" ng-click="clickContent()">自定義</label>
    </div>
</div>

那么其效果:

image_1bvme9gdvd3u31nm0i3c612uf9.png-6.3kB

更詳細的資料:
AngularJs checkbox綁定
Angularjs checkbox的ng屬性


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM