2016-12-16 58 views

回答

0

我定你的plunker: https://plnkr.co/edit/T0AAG5mY80hDNzVLKoKp?p=preview

(function() { 
// Code goes here 
angular 
.module('plunker', ['formly', 'formlyBootstrap']) 
.controller('mainCtrl', function($scope) { 
    console.log('mainCtrl is Loaded'); 
    var vm = this; 

    vm.fields = [{ 
     key: 'id', 
     type: 'input', 
     templateOptions: { 
     type: 'number', 
     label: 'Id', 
     placeholder: 'Enter Id', 
     required: true 
     } 
    }, { 
     key: 'name', 
     type: 'input', 
     templateOptions: { 
     type: 'text', 
     label: 'Name', 
     placeholder: 'Enter ur Name', 
     required: true 
     } 
    }]; 
}); 
})(); 

你失蹤了額外的 「}」 後的第一個templateOptions,並有一些其他的東西我做到了。我通常將任何js文件封裝在一個閉包中,並且它不適合使用var和angular,只需鍵入angular然後輸入.module或.controller即可。如果你只是在學習角度,你應該拋棄控制器並學習組件,因爲這是現在正確的方式。

此外,對庫的引用不正確......其中一些鏈接不再工作。通過F12快速查看調試器會發現這些問題。