Angular Schema表单未显示

时间:2015-09-01 09:59:52

标签: angularjs angular-schema-form

我正在使用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不会显示代码,但我没有错误消息。

1 个答案:

答案 0 :(得分:2)

我找到了解决方案。

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

$scope.$broadcast('schemaFormRedraw');