LoginSignup
0
0

More than 5 years have passed since last update.

Angular : *ngIf文でワイルドカード使えなかたよ…

Last updated at Posted at 2019-04-21

Angular : *ngIf文でワイルドカード使えなかたよ…

下記のようなコード、urlに応じて表示を条件分岐したい時。

<div *ngIf="route.url === '/page-top' || route.url === 'page-top/*'">

urlがhttps://<ドメイン名>/page-topか、もしくはhttps://<ドメイン名>/page-top/<すべてのChildコンポーネント>の場合、という条件文。

もうhttps://<ドメイン名>/page-top以下のChildコンポーネントはすべて条件に含めたいのだよ、ということでとっさに思いつくのがなんにでも一致を意味するワイルドカード'*'だと思うのだけど。


使えません。


いちおうこんな方法がありました。

<div *ngIf="route.url === '/page-top' || route.url.includes('/page-top')">


router.url.include('...')という構文。


以上。

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0