码迷,mamicode.com
首页 > Web开发 > 详细

[AngularJS] angular-formly: Extending Types

时间:2015-05-21 06:33:37      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

Extending types is one of the ways that makes angular-formly help you keep your Angular forms DRY. When use responsibly, they can make it much easier to manage common types, allowing you to add a bit of functionality to a common type.

 

(function() {

    ‘use strict‘;

    var app = angular.module(‘formlyExample‘, [‘formly‘, ‘formlyBootstrap‘]);
    
    app.run(function(formlyConfig) {
        formlyConfig.setType({
            name: ‘avengersSelect‘,
            extends: ‘select‘,
            defaultOptions: {
                templateOptions: {
                    label: ‘Favorite Avenger‘,
                    options: [
                        {name: ‘Iron Man‘, value: ‘iron_man‘},
                        {name: ‘Captain America‘, value: ‘captain_america‘},
                        {name: ‘Black Widow‘, value: ‘black_widow‘},
                        {name: ‘Hulk‘, value: ‘hulk‘},
                        {name: ‘Thor‘, value: ‘thor‘}
                    ]
                }
            }
        });
    })

    app.controller(‘MainCtrl‘, function MainCtrl($timeout) {
        var vm = this;
        vm.model = {};
        vm.fields = [
            {
                type: ‘avengersSelect‘,
                key: "avengersSelect"
            },
            {
                type: ‘avengersSelect‘,
                key: "avengersSelect2",
                templateOptions: {
                    label: ‘Favorite Avenger 2‘,
                    options: [
                        {name: ‘Iron Man‘, value: ‘iron_man‘},
                        {name: ‘Captain America‘, value: ‘captain_america‘},
                        {name: ‘Black Widow‘, value: ‘black_widow‘},
                        {name: ‘Hulk‘, value: ‘hulk‘},
                        {name: ‘Thor‘, value: ‘thor‘}
                    ]
                }
            }

        ];
    });
})();

 

[AngularJS] angular-formly: Extending Types

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/4518666.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!