【问题标题】:How to compile html form template to html string如何将html表单模板编译为html字符串
【发布时间】:2016-12-30 04:59:19
【问题描述】:

我有一个这样的对象:

$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>

【问题讨论】:

    标签: javascript html angularjs templates render


    【解决方案1】:

    您可以将您的模板包含在:

    <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>
    

    【讨论】:

    • 你不懂我的意思。我想用 angularjs 创建 html 生成器。我想生成像这样可复制的 html bootsnipp.com/forms
    猜你喜欢
    • 1970-01-01
    • 2016-02-23
    • 1970-01-01
    • 2018-08-30
    • 1970-01-01
    • 1970-01-01
    • 2016-08-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多