[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;
                    }
                }
            }
        ];
    });

})();

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。