zoukankan      html  css  js  c++  java
  • [AngularJS] Introduction to angular-formly

    <!DOCTYPE html>
    <html>
    
    <head>
        <!-- Each of these scripts are the latest version of the library at the time this jsbin was created -->
    
        <!-- Twitter bootstrap -->
        <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css"/>
        <!-- api-check is a dependency of angular-formly -->
        <script src="bower_components/api-check/dist/apiCheck.min.js"></script>
    
        <!-- angular.js is a dependency of angular-formly (obviously) -->
        <script src="bower_components/angular/angular.min.js"></script>
    
        <!-- This is angular-formly -->
        <script src="bower_components/angular-formly/dist/formly.min.js"></script>
    
        <!-- This is a bootstrap template libraray giving us some pre-defined types for bootstrap -->
        <script src="//rawgit.com/formly-js/angular-formly-templates-bootstrap/4.0.3/dist/angular-formly-templates-bootstrap.js"></script>
    
        <title>Angular Formly Lesson</title>
    </head>
    
    <body ng-app="formlyExample" ng-controller="MainCtrl as vm">
    <div>
        <h1>
            angular-formly: Introduction<br />
            <small>Egghead.io lesson by @kentcdodds</small>
        </h1>
        <form name="vm.form" ng-submit="vm.onSubmit()" novalidate>
            <formly-form model="vm.model" fields="vm.fields"></formly-form>
            <button type="submit" class="btn btn-primary submit-button">Submit</button>
        </form>
    
        <form name="vm.form" ng-submit="vm.onSubmit()" novalidate>
            <div class="form-group">
                <label for="firstName">First Name</label>
                <input ng-model="vm.model.firstName" id="firstName" name="firstName" class="form-control" />
            </div>
            <button type="submit" class="btn btn-primary submit-button">Submit</button>
        </form>
        <h2>Model</h2>
        <pre>{{vm.model | json}}</pre>
        <h2>Fields <small>(note, functions are not shown)</small></h2>
        <pre>{{vm.originalFields | json}}</pre>
        <h2>Form</h2>
        <pre>{{vm.form | json}}</pre>
    </div>
    <script src="app.js"></script>
    </body>
    
    </html>
    /* global angular */
    (function() {
    
        'use strict';
    
        var app = angular.module('formlyExample', ['formly', 'formlyBootstrap']);
    
        app.controller('MainCtrl', function MainCtrl() {
            var vm = this;
            // funcation assignment
            vm.onSubmit = onSubmit;
    
            // variable assignment
            vm.model = {
                firstName: 'Obi Wan',
                something: {name: "default",value:"default"}
            };
            vm.fields = [
                {
                    type: 'input',
                    key: 'firstName',
                    templateOptions: {
                        label: 'First Name'
                    }
                },
                {
                    template: '<hr />'
                },
                {
                    type: 'select',
                    key: 'something',
                    templateOptions: {
                        label: 'Select Somthing',
                        options: [
                            {name: "wan", value: "Wan"},
                            {name: "obi", value: "Obi"},
                            {name: "Yui", value: "yui"}
                        ]
                    }
                }
            ];
    
    
            // copy fields because formly adds data to them
            // that is not necessary to show for the purposes
            // of this lesson
            vm.originalFields = angular.copy(vm.fields);
    
            // function definition
            function onSubmit() {
                alert(JSON.stringify(vm.model), null, 2);
            }
        });
    
    })();
  • 相关阅读:
    Lesson 1#05-用户交互和注释
    Lesson 1#04-变量与常量
    Lesson 1#03-Python安装与Hello Python World
    elementUI 表格之合并同类项(包括行和列)
    elementUI 表格之表头合并
    VSCode关于编译scss的插件
    elementUI中的级联选择器,默认赋值不起作用
    highcharts中的环形图
    highcharts中的折线图
    highcharts中的仪表盘样式
  • 原文地址:https://www.cnblogs.com/Answer1215/p/4345719.html
Copyright © 2011-2022 走看看