Home Angular 4+ : Why isn't ng-if working in app.componet.html?
Reply: 0

Angular 4+ : Why isn't ng-if working in app.componet.html?

user1287
1#
user1287 Published in April 21, 2018, 3:27 pm

I am currently trying to use an ng-if directive in my app.component.html file:

<p>This should appear.</p>

<p ng-if="0==1">This shouldn't, but it does.</p>

My app.component.ts file looks like this:

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent {
}

I have tried numerous different values instead of 0==1 and it still doesn't work, including using the value of a passed-in variable. It is compiling and displaying without errors, but is not removing the second p.

I have also tried *ng-if. When I do that, I get an error:

Template parse errors:

Can't bind to 'ng-if' since it isn't a known property of 'p'. ("<p>This should appear.</p>

<p [ERROR ->]*ng-if="0==1">This shouldn't, but it does.</p>

"): ng:///AppModule/AppComponent.html@2:3
Property binding ng-if not used by any directive on an embedded template. 
Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". ("<p>This should appear.</p>
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.31241 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO