Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 角度模式表单:向表单字段添加自定义html_Angularjs_Angular Schema Form - Fatal编程技术网

Angularjs 角度模式表单:向表单字段添加自定义html

Angularjs 角度模式表单:向表单字段添加自定义html,angularjs,angular-schema-form,Angularjs,Angular Schema Form,我刚刚开始研究角度模式表单,所以这可能是我在文档或描述中遗漏的内容 我试图做的是在生成的表单字段的标签和字段本身旁边添加一个图标。像这样: 但开箱即用的角度模式表单将生成: 我知道我可以创建自己的自定义字段类型,但这就是方法吗?这需要我在自定义变量中重新定义所有字段类型,因为我需要这两个图标及其在所有表单字段上的功能 我希望有一种更简单的方法将此功能添加到生成的html中,并有一种简单的方法在其上添加功能(ng click function) 编辑:再次阅读文档后,我发现我需要定义自己的自定

我刚刚开始研究角度模式表单,所以这可能是我在文档或描述中遗漏的内容

我试图做的是在生成的表单字段的标签和字段本身旁边添加一个图标。像这样:

但开箱即用的角度模式表单将生成:

我知道我可以创建自己的自定义字段类型,但这就是方法吗?这需要我在自定义变量中重新定义所有字段类型,因为我需要这两个图标及其在所有表单字段上的功能

我希望有一种更简单的方法将此功能添加到生成的html中,并有一种简单的方法在其上添加功能(ng click function)

编辑:再次阅读文档后,我发现我需要定义自己的自定义字段类型()

根据我收集的信息,我需要将以下内容添加到我的模块配置块中:

schemaFormDecoratorsProvider.addMapping(
    'bootstrapDecorator',
    'custominput',
    'shared/templates/customInput.tpl.html',
    sfBuilderProvider.builders.sfField
);
我还将
shared/templates/customInput.tpl.html
的内容添加到
$templatesCache

但是当我试图呈现一个表单时,使用类似

"schema": {
    "type": "object",
    "properties": {
        "firstName": {
            "title": "First name",
            "type": "string"
        },
        "lastName": {
            "title": "Last name",
            "type": "custominput"
        },
        "age": {
            "title": "Age",
            "type": "number"
        }
    }
}
我只看到第一个字段(名字)和年龄。自定义类型被忽略

我已经尝试过调试解决这个问题的方法,但据我所知,自定义字段已正确添加到装饰器中。我尝试将
schemaFormDecoratorsProvider.decorator()
记录到console.log中,在那里我可以看到我的自定义字段类型

我还尝试在控制器中触发
$scope.$broadcast('schemaFormRedraw')
,但我仍然只看到内置字段类型

作为测试,我尝试定义自己的decorator,覆盖默认引导decorator:

schemaFormDecoratorsProvider.defineDecorator('bootstrapDecorator', {           
    'customType': {template: 'shared/templates/customInput.tpl.html', builder: sfBuilderProvider.stdBuilders},
    // The default is special, if the builder can't find a match it uses the default template.
    'default': {template: 'shared/templates/customInput.tpl.html', builder: sfBuilderProvider.stdBuilders},
}, []);
我希望看到所有字段呈现为相同的,因为我只定义了一个默认类型和我自己的自定义类型。但是,我仍然只看到呈现的内置类型,我的custominput一直被忽略


我遗漏了什么?

我也遇到了同样的问题,问题是您不应该将JSON模式与表单定义混淆

要呈现自定义组件,必须更改表单定义。即,在控制器中,您的标准表单定义可能类似于:

$scope.form = [
    "*",
    {
      type: "submit",
      title: "Save"
    }
  ];
您必须将此更改为:

$scope.form = [
    "firstName",
    "age",
    {
        key:"lastName",
        type:"customInput"
    },
    {
      type: "submit",
      title: "Save"
    }
  ];

你有没有找到答案?我面临着完全相同的问题