【问题标题】:Text inside tag outside of output tag in Angular.jsAngular.js中输出标签外标签内的文本
【发布时间】:2013-08-16 15:47:17
【问题描述】:

我在 HTML 中有一个链接标签:

<link url="http://google.com">google</link>

以及将其转换为&lt;a&gt; 标签的代码:

app.directive('link', function() {
    return {
        restrict: 'E',
        transclude: true,
        replace: true,
        scope: {
            url: '@'
        },
        template: '<a href="{{url}}" ng-transclude></a>'
    }
});

但是使用这个文本谷歌在外面并且 URL 没有被删除(如果从链接到标签,它会复制)。如果我使用属性,它可以正常工作&lt;div link url="http://google.com"&gt;google&lt;/div&gt; 怎么了?

这里是
jsFiddle

【问题讨论】:

    标签: javascript html angularjs angularjs-directive


    【解决方案1】:

    我想我知道其中的原因,link if html 标记(从头到包含样式表)是单个自闭合标记,它说明了解析器在执行 Angular 之前如何解析它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-24
      • 1970-01-01
      • 1970-01-01
      • 2016-10-17
      • 1970-01-01
      相关资源
      最近更新 更多