当前位置: 首页 > 工具软件 > Formly > 使用案例 >

[AngularJS] angular-formly: expressionProperties

曾河
2023-12-01

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

})();

 

 类似资料: