2016-09-19 73 views
0

我對Angular Schema形式是全新的,並且試圖創建一些形式來顯示在我的html頁面上。我想知道如何以及如何在this page中定義form contentschema content。我在哪些文件中放置這些代碼行,以及如何調用要在HTML頁面中顯示的表單?Angular Schema Forms

[ 
    "name", 
    "email", 
    { 
    "key": "comment", 
    "type": "textarea", 
    "placeholder": "Make a comment" 
    }, 
    { 
    "type": "submit", 
    "style": "btn-info", 
    "title": "OK" 
    } 
] 

模式

{ 
    "type": "object", 
    "title": "Comment", 
    "properties": { 
    "name": { 
     "title": "Name", 
     "type": "string" 
    }, 
    "email": { 
     "title": "Email", 
     "type": "string", 
     "pattern": "^\\[email protected]\\S+$", 
     "description": "Email will be used for evil." 
    }, 
    "comment": { 
     "title": "Comment", 
     "type": "string", 
     "maxLength": 20, 
     "validationMessage": "Don't be greedy!" 
    } 
    }, 
    "required": [ 
    "name", 
    "email", 
    "comment" 
    ] 
} 

幫助在這方面有一些詳細的初級支持的準則將非常感激。

回答

0

一種方法是在您選擇的控制器中提供架構和實例數據。

文檔wiki提供了一個basic example,您應該在其中獲得所有必要的信息。

控制器:

angular.module('myModule', ['schemaForm']) 
     .controller('FormController', function($scope) { 
    $scope.schema = { 
    type: "object", 
    properties: { 
     name: { type: "string", minLength: 2, title: "Name", description: "Name or alias" }, 
     title: { 
     type: "string", 
     enum: ['dr','jr','sir','mrs','mr','NaN','dj'] 
     } 
    } 
    }; 

    $scope.form = [ 
    "*", 
    { 
     type: "submit", 
     title: "Save" 
    } 
    ]; 

    $scope.model = {}; 
} 

模板:

<div ng-controller="FormController"> 
    <form sf-schema="schema" sf-form="form" sf-model="model"></form> 
</div> 
+0

所以,我該把這個代碼在控制器內的JavaScript文件,並從我的html頁面調用它呢? (忍受我,對此非常陌生) –

+0

是的,把它放在一個JavaScript文件中,並將其包含在html模板中。我將模板代碼添加到我的答案中。 – kenda

+0

非常感謝。我也想知道我需要在html文件的''部分鏈接哪些外部資源才能使其工作 –