我正在使用Angular Schema Form生成带有JSON Schema的表单 我想在用户输入字符串abc时显示电子邮件文本字段,但是在输入abc后电子邮件文本字段永远不会出现。我认为问题出在变量名称的范围或条件:“name =='abc'” 你可以帮个忙吗?有代码
HTML
<html ng-app="myApp">
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="bower_components/angular/angular.js" type="text/javascript"></script>
<script src="bower_components/angular-sanitize/angular-sanitize.js" type="text/javascript"></script>
<script src="bower_components/tv4/tv4.js" type="text/javascript"></script>
<script src="bower_components/objectpath/lib/ObjectPath.js" type="text/javascript"></script>
<script src="bower_components/angular-schema-form/dist/schema-form.js" type="text/javascript"></script>
<script src="bower_components/angular-schema-form/dist/bootstrap-decorator.js" type="text/javascript"></script>
<script src="js/app.js" type="text/javascript"></script>
</head>
<body ng-controller="myCtrl">
<form sf-schema="schema" sf-form="form" sf-model="model"></form>
</body>
</html>
app.js
var myApp = angular.module("myApp", ['schemaForm']);
myApp.controller("myCtrl", function ($scope) {
$scope.schema = {
"type": "object",
"title": "Comment",
"properties": {
"name": {
"title": "Name",
"type": "string"
},
"email": {
"title": "Email",
"type": "string"
}
}
};
$scope.form = [
"name",
{key: "email",
condition: "name=='abc'"
},
{
"type": "submit",
"style": "btn-info",
"title": "OK"
}
];
$scope.model = {};
});
答案 0 :(得分:1)
在docs中,您可以看到您无法直接使用名称,因为条件适用于范围内的任何内容,而不仅仅是模型。因此,将“name”替换为“model.name =='abc'”就行了。查看我的example here。