Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
*ngIf的Angular2@Input不工作(null)_Angular_Angular Ng If - Fatal编程技术网

*ngIf的Angular2@Input不工作(null)

*ngIf的Angular2@Input不工作(null),angular,angular-ng-if,Angular,Angular Ng If,我使用的是~2.1.1版 我在这里尝试了答案,但没有任何建议对我有效: 这是我在另一个组件中使用的微调器组件: import {Component} from '@angular/core' import {Post} from './post' import {PostsService} from './posts.service' @Component({ selector: 'home', template: `<h2>Posts</h2>

我使用的是~2.1.1版

我在这里尝试了答案,但没有任何建议对我有效:

这是我在另一个组件中使用的微调器组件:

import {Component} from '@angular/core'
import {Post} from './post'
import {PostsService} from './posts.service'


@Component({
    selector: 'home',
    template: `<h2>Posts</h2>

        <spinner [visible]="isloading"></spinner>

        <ul *ngFor="let post of posts" class="list-group">

            <li class="list-group-item"> {{post.body}}  </li>

        </ul>
    `,
    providers:[PostsService],

})

export class PostsComponent{

    posts:Post[];
    isLoading:boolean = true;

    constructor(private _postsService: PostsService){

   }

     ngOnInit(){

       this._postsService.getPosts()
            .subscribe(posts => {
                this.isLoading = false;
                this.posts = posts;
            });
     }


}
从'@angular/core'导入{Component}
从“/Post”导入{Post}
从“./posts.service”导入{PostsService}
@组成部分({
选择器:“主页”,
模板:`员额

  • {{post.body}
  • `, 提供者:[售后服务], }) 导出类PostsComponent{ 职位:职位[]; isLoading:布尔值=true; 构造器(专用postsService:postsService){ } 恩戈尼尼特(){ 这个。_postsService.getPosts() .订阅(帖子=>{ this.isLoading=false; 这个.posts=posts; }); } }
    以下是在浏览器中为标记输出的内容:

    <!--template bindings={
      "ng-reflect-ng-if": null
    }-->
    
    
    

    我还尝试在ngOnInit()中将“可见”初始化为true,微调器将显示,但我无法通过将isloading设置为false再次隐藏它

    模板和组件之间的变量名称不同

    在模板中有“isloading”,在组件中有“isloading”


    大小写很重要。

    模板和组件之间的变量名称不同

    在模板中有“isloading”,在组件中有“isloading”


    大小写很重要。

    听起来您的isloading属性没有绑定到模板。您可能想发布其他组件。请将其他组件发布到包含微调器组件的位置。我发布了其他组件。我看到了——应该是“isLoading”而不是“isLoading”,很高兴您已经解决了:)听起来您的isLoading属性没有绑定到模板。您可能想发布其他组件。请将其他组件发布到包含微调器组件的位置。我发布了其他组件我看到了--应该是“isLoading”而不是“isLoading”,很高兴您解决了它:)