是否可以编译此html模板字符串:
"<p>List of products from {{supplier.name}}</p>
<p ng-repeat="ref in refs">{{ref}}</p>"
Run Code Online (Sandbox Code Playgroud)
直接到一个html字符串,如:
"<p>List of products from Some Supplier</p>
<p>a0120</p>
<p>a0241</p>
<p>z1242</p>
<p>z3412</p>"
Run Code Online (Sandbox Code Playgroud)
或至少不太干净的版本:
"<p class="ng-scope ng-binding">List of product from Duval</p>
<!-- ngRepeat: ref in refs track by $index -->
<p ng-repeat="ref in refs track by $index" class="ng-scope ng-binding">a0120</p>
<p ng-repeat="ref in refs track by $index" class="ng-scope ng-binding">a0241</p>
<p ng-repeat="ref in refs track by $index" class="ng-scope ng-binding">z1242</p>
<p ng-repeat="ref in refs track by $index" class="ng-scope ng-binding">z3412</p>"
Run Code Online (Sandbox Code Playgroud)
我尝试使用$ compile(templateStr)($ scope),但返回的dom元素未完全处理.但是我没有使用以下指令将其编译为页面元素,并且检查该元素我可以看到它具有我正在寻找的最终html:
app.directive('compile', function($compile) { …Run Code Online (Sandbox Code Playgroud) 我有一个my-edit指令,它有一个value属性,期望绑定一个scope变量.
<my-edit value="myVar"></my-edit>
Run Code Online (Sandbox Code Playgroud)
有没有办法做这样的事情:
<my-edit value="{{varName}}"></my-edit>
Run Code Online (Sandbox Code Playgroud)
其中varName ="myVar"
我想将此指令嵌套在具有"text-field"属性的"my-listbox"指令中
<my-listbox ng-model="myList" text-field="itemProp"></my-listbox>
Run Code Online (Sandbox Code Playgroud)
所以我尝试使用如下模板:
<div>
<ul>
<li ng-repeat="item in items">
<my-edit value="item.{{textField}}"></my-edit>
</li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
但显然它不起作用
我想使用文本绑定也不是解决方案.
是一个动态生成的模板"my-listbox"的方式去哪里?
我在编译函数中尝试过,但由于嵌套的neRepeat指令,它没有那么好用.应该在链接函数中使用$ compile吗?
谢谢