0

Its not Angular 4 !!!

Just tried *ngIf getting error

I want to use ngIf condition where if length of the array is 0 display error message

Can any one help on this.

<div class="panel-body">
   <div *ngFor ="let repo of repos">
       <div *ngIf="repo?.length = 0"> No repos </div>
           <div class="row">
            <div class="col-md-9">
            <h4><a target = "_blank" href="{{repo.html_url}}">{{repo.name}}</a></h4>
            <p>{{repo.description}}</p>
             </div>
             <div class="col-md-3">
             <span class="label label-default">{{repo.watchers}} Watchres</span>
             <span class="label label-primary">{{repo.forks}} Forks</span>
              </div>
            </div>
           <hr>
         </div>
       </div>
R9102
  • 687
  • 1
  • 9
  • 32
  • There is no `else` in `*ngIf` in Angular 2. `else` was added in Angular 4. You can check the changelog for details. – Günter Zöchbauer Aug 27 '17 at 13:59
  • 1
    https://github.com/angular/angular/blob/master/CHANGELOG.md So are you actually using Angular 2? If you are using Angular 4 see https://stackoverflow.com/questions/43006550/how-to-use-ngif-else-in-angular-4 – Günter Zöchbauer Aug 27 '17 at 14:03
  • 1
    Even though I have Angular 4 and can use ngIf else, I never do. It is really unwieldy and doesn't really add any functionality that can't be accomplished more simply with 2 opposing ngIf's. :-/ – diopside Aug 27 '17 at 14:07
  • @GünterZöchbauer i am discussing about angular 2 ....not 4 – R9102 Aug 27 '17 at 14:34
  • also rectifying with my errors.... You made it dupilcate... – R9102 Aug 27 '17 at 14:35
  • As I mentioned altrady, there is no `else` in Angular2. Just use a 2nd ngif with `!` (for "not") or upgrade to Angular 4. There is usually no point in staying with an old version. – Günter Zöchbauer Aug 27 '17 at 14:41
  • repo: where you declare use like this repo: Array = []; and see if it works, I guess you are using repo: any; – Ali Adravi Aug 27 '17 at 17:35

0 Answers0