简体   繁体   English

如何在带有打字稿的Ionic 2.0中包含angular-schema-form

[英]How to include angular-schema-form in Ionic 2.0 with typescript

I've started to build an app with ionic from scratch and liked to include the http://schemaform.io framework. 我已经开始从头开始构建一个带有离子的应用程序,并且喜欢包含http://schemaform.io框架。

I have no problems with running the example in a webpage but I failed to do so with ionic. 我在网页上运行示例没有问题,但我没有使用离子这样做。

I have created the project with 我用它创建了这个项目

ionic start form blank --v2 --ts

I have linked the js files in the index.html 我已经链接了index.html中的js文件

  <script type="text/javascript" src="build/js/libs/schema-form/angular.min.js"></script>
  <script type="text/javascript" src="build/js/libs/schema-form/angular-sanitize.min.js"></script>
  <script type="text/javascript" src="build/js/libs/schema-form/tv4.js"></script>
  <script type="text/javascript" src="build/js/libs/schema-form/ObjectPath.js"></script>
  <script type="text/javascript" src="build/js/libs/schema-form/schema-form.min.js"></script>
  <script type="text/javascript" src="build/js/libs/schema-form/bootstrap-decorator.min.js"></script> 

Then I have editet the home.html file like this: 然后我编辑了home.html文件,如下所示:

<ion-content padding>
  <div ng-controller="FormController">
    <form sf-schema="schema" sf-form="form" sf-model="model"></form>
  </div>
</ion-content>

and the according home.ts file like this: 和相应的home.ts文件是这样的:

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';

import { FormPage } from 'schemaForm';


@Component({ templateUrl: 'build/pages/form/form.html', })
export class FormPage { constructor(private navCtrl: NavController) {

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 = {}; });
  }

What I wanted to reach with this? 我想用这个来达到什么目的? I'd liked to put the example form in an ionic app. 我想把这个示例表单放在一个离子应用程序中。 I like the idea behind schema form because it is easy to understand for me but I fail to bind the form in an app framework. 我喜欢模式形式背后的想法,因为它很容易理解,但我无法在应用程序框架中绑定表单。 Every help is very welcome ... 非常欢迎每一个帮助......

I don't think that what you are trying to achieve is really possible since angular-schema-form is still as per this day only for angularjs while ionic 2+ is using angular. 我不认为你想要实现的是真正可能的,因为角度图式形式仍然只在今天只有angularjs而离子2+使用角度。

Here is the issue to tack the progress of moving to angular 2+ 这是解决转向角度2+的进展的问题

But in the meantime you can use https://github.com/makinacorpus/angular2-schema-form for what you are trying to achieve. 但与此同时,您可以使用https://github.com/makinacorpus/angular2-schema-form来实现您的目标。 Its works just as angular-schema and was made for angular 2+. 它的工作方式与角度图案一样,是为角度2+而制作的。

Here is the plugin for JSON Schema form in IONIC that uses angular2 JSON schema in the backend. 这是IONIC中JSON Schema表单的插件,它在后端使用angular2 JSON模式。 Here is the npm link: https://www.npmjs.com/package/ionic-json-schema-form 这是npm链接: https ://www.npmjs.com/package/ionic-json-schema-form

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM