如何将 html 表单模板编译为 html 字符串
How to compile html form template to html string
我有一个这样的对象:
$scope.item ={
fieldName:'First Name',
fieldModel:'user.firstname',
placeholder:'enter your name'
}
我想像这样编译这个 html 表单模板:
<script type="text/ng-template" id="input.html">
<div class="items form-group">
<label class="col-sm-2 control-label">
{{item.fieldName}}
</label>
<div class="col-sm-10">
<input type="text" ng-model="{{item.fieldModel}}" placeholder="{{item.placeholder}}" class="form-control">
</div>
</div>
</script>
到html使用纯html设计的字符串:
<div class="items form-group">
<label class="col-sm-2 control-label">
First Name
</label>
<div class="col-sm-10">
<input type="text" ng-model="user.firstname" placeholder="enter your name" class="form-control">
</div>
</div>
您可以包含您的模板:
<div id="tpl-content" ng-include src="input.html"></div>
但您的模板应该是:
<script type="text/ng-template" id="input.html">
<div class="items form-group">
<label class="col-sm-2 control-label">
{{item.fieldName}}
</label>
<div class="col-sm-10">
<input type="text" ng-model="item.fieldModel" placeholder="{{item.placeholder}}" class="form-control">
</div>
</div>
我有一个这样的对象:
$scope.item ={
fieldName:'First Name',
fieldModel:'user.firstname',
placeholder:'enter your name'
}
我想像这样编译这个 html 表单模板:
<script type="text/ng-template" id="input.html">
<div class="items form-group">
<label class="col-sm-2 control-label">
{{item.fieldName}}
</label>
<div class="col-sm-10">
<input type="text" ng-model="{{item.fieldModel}}" placeholder="{{item.placeholder}}" class="form-control">
</div>
</div>
</script>
到html使用纯html设计的字符串:
<div class="items form-group">
<label class="col-sm-2 control-label">
First Name
</label>
<div class="col-sm-10">
<input type="text" ng-model="user.firstname" placeholder="enter your name" class="form-control">
</div>
</div>
您可以包含您的模板:
<div id="tpl-content" ng-include src="input.html"></div>
但您的模板应该是:
<script type="text/ng-template" id="input.html">
<div class="items form-group">
<label class="col-sm-2 control-label">
{{item.fieldName}}
</label>
<div class="col-sm-10">
<input type="text" ng-model="item.fieldModel" placeholder="{{item.placeholder}}" class="form-control">
</div>
</div>