[AngularJS] angular-formly: expressionProperties

angular-formly provides a very simple API to dynamically change properties of your field (like disabled, hidden, and required) using the powerful expressionProperties property on your field.

 

(function() {

    'use strict';

    var app = angular.module('formlyExample', ['formly', 'formlyBootstrap']);

    app.controller('MainCtrl', function MainCtrl() {
        var vm = this;
        vm.model = {};
        vm.fields = [
            {
                type: 'checkbox',
                key: "control",
                templateOptions: {
                    label: 'Click to show'
                }
            },
            {
                type: 'input',
                key: "nothing",
                templateOptions: {
                    label: "Show when checkbox checked"
                },
                expressionProperties: {
                    hide: function($viewValue, $modelValue, scope) {
                        console.log(scope.model.control);
                        return !scope.model.control;
                    }
                }
            }
        ];
    });

})();

 

posted @ 2015-05-07 03:13  Zhentiw  阅读(531)  评论(0编辑  收藏  举报