简体   繁体   English

Angular 2和webpack:意外的结束标记“ a”

[英]Angular 2 and webpack: unexpected closing tag “a”

I have this Angular 2 template which display tabs of my Web site: 我有这个Angular 2模板,它显示我的网站的选项卡:

<div id="menu">
    <ul id="tabs">
        <li *ngFor="let tab of tabs; let i = index" [class.active]="selectedTab===i">
            <a routerLink="/private/home/{{i}}">{{tab}}</a>
        </li>
    </ul>
</div>

<div class="tabContent">
    <span *ngIf="selectedTab==0"><welcome></welcome></span>
    <span *ngIf="selectedTab==1"><boiler></boiler></span>
</div>

It works perfectly well. 效果很好。 Then, I try to use Webpack with default option to create unique *.js file: it still works. 然后,我尝试使用带有默认选项的Webpack来创建唯一的* .js文件:它仍然可以工作。 Finally, in Webpack, I active the option to minimize the .js file and I get this error: 最后,在Webpack中,我激活了用于最小化.js文件的选项,并且出现此错误:

Unexpected closing tag "a" (" of tabs; let i = index" [class.active]="selectedTab===i">
<a routerlink=/private/home/{{i}}>{{tab}}[ERROR ->]</a> </li> </ul> </div>                 
<div class=tabContent> <span *ngif="selectedTab==0"><welcome></welcome></span")

Any idea on this error ? 对这个错误有任何想法吗?

Here the related code generated by Webpack: 这里是Webpack生成的相关代码:

function(t,e){t.exports='<div id=menu> <ul id=tabs> <li *ngfor="let tab of tabs; 
let i = index" [class.active]="selectedTab===i"> 
<a routerlink=/private/home/{{i}}>{{tab}}</a> </li> </ul> </div> <div class=tabContent> 
<span *ngif="selectedTab==0"><welcome></welcome></span> <span *ngif="selectedTab==1">
<boiler></boiler></span> </div>'}

I guess the issue is with the htmlLoader . 我猜问题出在htmlLoader Depending on your webpack version you should set the minimize option to false in your webpack configuration. 根据您的WebPack版本,你应该设置minimize在你的WebPack配置选项设置为false。

webpack 1 (inside the root of your configuration) webpack 1 (在配置根目录内)

htmlLoader: {
    minimize: false
},

webpack 2 webpack 2

plugins: [
    new webpack.LoaderOptionsPlugin({
        options : {
            htmlLoader : {
                minimize : false
            }
        }
    })

]

/private/home/{{i}} -> this is not in "". / private / home / {{i}}->不在“”中。

try this for routerLink 试试这个routerLink

<a [routerLink]="['/private/home/',i]">{{tab}}</a>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM