相关疑难解决方法(0)

如何在Angular 2中的同一组件中使用多个ng-content?

我想在我的组件中显示不同的模板.只有一个会显示.如果hasURLtrue,我想表明<a></a>.如果hasURLfalse,我想表明<button></button>.

问题如果hasURL为false,组件显示按钮,但ng-content为空.因为它已经在第一篇中读到了"a></a>

有没有办法解决这个问题?

        <a class="bouton" href="{{ href }}" *ngIf="hasURL">
            <ng-content>
            </ng-content>
        </a>

        <button class="bouton" *ngIf="!hasURL">
            <ng-content>
            </ng-content>    
        </button>
Run Code Online (Sandbox Code Playgroud)

谢谢!

javascript angular2-directives angular2-template angular

38
推荐指数
1
解决办法
1万
查看次数

多个命名路由器出口角度2

我希望通过子路径显示不同的视图.例如,我希望我的模板能够容纳多个路由器插座

Version: @angular/router": "3.0.0-alpha.7"

<router-outlet></router-outlet>
<router-outlet name="route1"></router-outlet>
<router-outlet name="route2"></router-outlet>
Run Code Online (Sandbox Code Playgroud)

在我的路由器中,我想指定路由器的名称.

正如我在一个问题中看到的,解决方法是指定AuxRoute,但此版本中不存在AuxRoute.

{path: '/',        component: HomeComponent, as: 'Home'},
new AuxRoute({path: '/route1', component: Route1Component, as: 'Route1'}),
new AuxRoute({path: '/route2', component: Route2Component, as: 'Route2'})
Run Code Online (Sandbox Code Playgroud)

虽然在角度2官方网站上我发现它可能有多个路由器,但我找不到任何资源.

https://angular.io/docs/ts/latest/guide/router.html

A template may hold exactly one unnamed <router-outlet>. The router supports multiple named outlets, a feature we'll cover in future.

angular-routing angular

16
推荐指数
1
解决办法
3万
查看次数