2

angular-schema-form用来显示和验证表单。

我的控制器中有这段代码:

MyApp.controller('formCtrl', ['$scope', '$rootScope','$state', '$http',
function ($scope, $rootScope,  $state, $http) {

    if (ENV != "dev") {
        formData = localStorage.getItem("signup.v-1.0.0.json")
        $scope.signupSchema=formData.schema;
        $scope.signupForm=formData.form;
        $scope.signupUser=formData.model;
    } else {
        // load the template and cache it
        $http.get("/forms/signup.v-1.0.0.json")
            .then(function (response) {
                console.log(response);
                // template loaded from the server
                $scope.signupSchema = response.data.schema;
                $scope.signupForm = response.data.form;
                $scope.signupUser=response.data.model;
                localStorage.setItem("signup.v-1.0.0.json", response.data);
            });

    }

}
]);

这在signup-v-1.0.0.json

{
  "schema":{
    "type": "object",
   "title": "Comment",
    "properties": {
      "name": {
        "title": "Name",
        "type": "string"
      },
      "email": {
        "title": "Email",
        "type": "string",
        "pattern": "^\\S+@\\S+$",
        "description": "Email will be used for evil."
      },
      "comment": {
        "title": "Comment",
        "type": "string",
        "maxLength": 20,
        "validationMessage": "Don't be greedy!"
      }
    },
    "required": [
      "name",
      "email",
      "comment"
    ]
  },
  "form":
  [
    "name",
    "email",
    {
      "key": "comment",
      "type": "textarea",
      "placeholder": "Make a comment"
    },
    {
      "type": "submit",
      "style": "btn-info",
      "title": "OK"
    }
  ],
  "model":
  {
  }
}

在我看来:

<div class="col-md-6">
            <div class="featured-box featured-box-secundary default h420">
                <div class="box-content" ng-controller="formCtrl">
                    <h4>Inscription</h4>

                    <p>Inscrivez vous en 2 minutes via ce formulaire.</p>

                    <form sf-schema="signupSchema" sf-form="signupForm" sf-model="signupUser"></form>

                </div>
            </div>
        </div>

我将schemaForm模块传递给我的应用程序:

 MyApp = angular.module('MyApp', ['ui.router','pascalprecht.translate','ui.bootstrap','Facebook','googleplus','mgo-angular-wizard','ui','ngMaterial','ngAria','ngAnimate','schemaForm']);

Chrome 不显示代码,但我没有错误消息。

4

1 回答 1

2

我找到了解决方案。

我需要广播'schemaFormRedraw'以重绘 ajax 加载结果中的表单,或者在本地存储中检索数据后:

$scope.$broadcast('schemaFormRedraw');
于 2015-09-01T10:40:34.360 回答