内联变量模板

时间:2017-04-11 06:33:16

标签: angularjs

我在角度控制器中有以下html

<div ng-include="'Module.' + entry.Module.View + '.template'"></div>

entry.Module.View的值是&#34; TextField&#34;。 在同一控制器内,此脚本标记存在:

<script type="text/ng-template" id="Module.TextField.template">
    <label>{{entry.Label}}</label>
    <input type="text" ng-model="entry.Value">
</script>

问题是这会尝试从外部源加载模板。是否有另一种标签或方法更适合从变量加载内联脚本模板?

1 个答案:

答案 0 :(得分:1)

您可以在控制器中创建变量,并使用element作为attribute而不是<ng-include src="moduleUrl"></ng-include>

vm

在控制器中,您有类似的东西(或者如果您使用$scope.moduleUrl = 'Module.' + $scope.entry.Module.View + '.template'; ,请相应更改)

<select id="search_database" class="form-control">
    <option value="1" selected="">Source 01</option>
    <option value="2">Source 02</option>
</select>
相关问题