So erstellen Sie eine Richtlinie auf eine dynamische Vorlage in AngularJS?

Wie kann ich erstellen Sie eine Richtlinie mit einem dynamischen template?

'use strict';

app.directive('ngFormField', function($compile) {
return {
    transclude: true,
    scope: {
        label: '@'
    },
    template: '<label for="user_email">{{label}}</label>',
    //append
    replace: true,
    //attribute restriction
    restrict: 'E',
    //linking method
    link: function($scope, element, attrs) {
        switch (attrs['type']) {
            case "text":
                //append input field to "template"
            case "select":
                //append select dropdown to "template"
        }
    }
  }
});
<ng-form-field label="First Name" type="text"></ng-form-field>

Dies ist, was ich jetzt haben, und es zeigt die Bezeichnung korrekt. Allerdings bin ich mir nicht sicher, wie das Anhängen zusätzlicher HTML-Vorlage. Oder die Kombination von 2 Vorlagen in 1.

InformationsquelleAutor teepusink | 2013-02-13
Schreibe einen Kommentar