在 ng-include 中使用变量作为表达式
Use variable as expression in ng-include
这段代码有效:
<div ng-include src="'Test.html'"></div>
此代码不会:
<div ng-include src="ctrl.URL"></div>
( ctrl.URL
设置为 "Test.html"
)。 我还将其设置为 'Test.html'
和 "'Test.html'"
具有相同的结果。
如何成功地将其转换为表达式以在 ng-include
src 中使用?我想我缺少一些关于如何解析字符串的知识,但我很确定'Test.html'
应该工作。
我发现我太无能了,无法重命名自己的变量。网址真的是控制。URl.现在一切正常。
检查一下,也许这个小提琴会对你有所帮助。
网页和模板:
<div ng-controller="Ctrl">
<select ng-model="template" ng-options="t.name for t in templates">
<option value="">(blank)</option>
</select>
url of the template: <tt>{{template.url}}</tt>
<hr/>
<div ng-include src="template.url" onload='myFunction()'></div>
</div>
<!-- template1.html -->
<script type="text/ng-template" id="template1.html">
Content of template1.html
</script>
<!-- template2.html -->
<script type="text/ng-template" id="template2.html">
<p ng-class="color">Content of template2.html</p>
</script>
控制器:
function Ctrl($scope) {
$scope.templates = [{
name: 'template1.html',
url: 'template1.html'},
{
name: 'template2.html',
url: 'template2.html'}];
$scope.template = $scope.templates[0];
$scope.myFunction = function() {
$scope.color = 'red';
}
}
相关文章:
- 在正则表达式中使用变量
- 使用一个表达式将两个变量分配给相同的值
- 从javascript表达式(Rhino)中获取变量
- 如何通过jsp表达式标记将java字符串变量传递给javascript函数
- 变量与表达式作为Javascript参数
- Javascript 复杂的正则表达式与变量
- Jquery 替换所有文本语法正则表达式中的变量
- 在 ng-include 中使用变量作为表达式
- 用于比较 HTML 标记内的变量的正则表达式
- 将变量传递到CasperJS中的XPath表达式中
- jstl-如何将表达式语言变量传递给javascript警报
- javascript中正则表达式(match)中变量的使用错误
- 如何将变量表达式转换为可执行代码(而不是替换值)
- javascript正则表达式:使用单词边界将变量传递给regexp
- 使用正则表达式中的变量与$和^匹配字符串
- 使用带有.match Regex表达式的变量的JavaScript
- 正则表达式提取PHP中的JavaScript变量
- 仅与字母字符匹配的正则表达式变量
- 使用正则表达式+变量的正则表达式
- 使用正则表达式变量作为普通变量- Javascript