Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.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
Javascript 如何制作一个;“装载”;角度2的屏幕_Javascript_Angularjs_Angular - Fatal编程技术网

Javascript 如何制作一个;“装载”;角度2的屏幕

Javascript 如何制作一个;“装载”;角度2的屏幕,javascript,angularjs,angular,Javascript,Angularjs,Angular,下午好,我是angular的初学者,我有以下疑问: 是否可以访问“我的所有组件”中的选择器 我带来的组件如下: Import {DownloadComponent} from '../loading/carregando.component'; @Component({ Selector: 'app-questions', TemplateUrl: './questions.component.html', StyleUrls: ['./questions.component.

下午好,我是
angular
的初学者,我有以下疑问:

是否可以访问“我的所有组件”中的选择器

我带来的组件如下:

Import {DownloadComponent} from '../loading/carregando.component';
@Component({
   Selector: 'app-questions',
   TemplateUrl: './questions.component.html',
   StyleUrls: ['./questions.component.css'],
   EntryComponents: [LoadingComponent]
})
@Injectable()
export class LoaderService{
    //BehaviorSubject takes an initial value false in this case and 
    //provides the most recent value where ever it has been subscribed to.  
    isRequesting: BehaviorSubject<boolean> = new BehaviorSubject(false);
    public setIsRequesting (bool:boolean){
        this.isRequesting.next(bool);
    }
    pubilc getIsRequesting: BehaviorSubject<boolean>{
        return this.isRequesting;
    }
}
export class AppComponent{
    isRequesting: boolean = false;
    constructor(private loaderService: LoaderService)
    ngOnInit(){
        loaderService.getIsRequesting().subscribe(value=>{
            this.isRequesting = value;
        })
    }
}
//make loader visible
loaderService.setIsRequesting(true);
//make loader hide
loaderService.setIsRequesting(false);
问题是,在任何我想要成本的html中,我都应该放置选择器

<loading [isRunning]="isRequesting"></loading>

我想把它放在一个地方,我在index.html中尝试过,但没有效果

有人知道如何帮助我吗?
谢谢

您需要导入加载组件,并通过将其包含在@component selector的指令数组中,将其设置为需要使用的组件的子组件


从angular 2的角度来看,这是有意义的,并且使其模块化了很多。要使用它,请在类中导入它并将其包含在指令数组中。然后,在模板中使用选择器。如果不导入,则不能在任何地方使用选择器

您需要导入加载组件,并通过将其包含在@component selector的指令数组中,将其设置为需要使用它的组件的子组件


从angular 2的角度来看,这是有意义的,并且使其模块化了很多。要使用它,请在类中导入它并将其包含在指令数组中。然后,在模板中使用选择器。如果不导入,则不能在任何地方使用选择器

补充Bharat所说的,您是否也将组件放入
app.module.ts
中?您应该将它包含在您的
@NgModule.declarations
中,然后将它包含在您想要使用的组件中。

补充Bharat所说的,您是否也将组件放入
app.module.ts
中?您应该将其包含在
@NgModule.declarations中,然后将其包含在您想要使用的组件中。

您可以将加载程序添加到应用程序的根组件中,并在根应用程序的模板中只添加一次选择器

完成后,您可以使用服务显示/隐藏正在加载的组件

您的服务将如下所示:

Import {DownloadComponent} from '../loading/carregando.component';
@Component({
   Selector: 'app-questions',
   TemplateUrl: './questions.component.html',
   StyleUrls: ['./questions.component.css'],
   EntryComponents: [LoadingComponent]
})
@Injectable()
export class LoaderService{
    //BehaviorSubject takes an initial value false in this case and 
    //provides the most recent value where ever it has been subscribed to.  
    isRequesting: BehaviorSubject<boolean> = new BehaviorSubject(false);
    public setIsRequesting (bool:boolean){
        this.isRequesting.next(bool);
    }
    pubilc getIsRequesting: BehaviorSubject<boolean>{
        return this.isRequesting;
    }
}
export class AppComponent{
    isRequesting: boolean = false;
    constructor(private loaderService: LoaderService)
    ngOnInit(){
        loaderService.getIsRequesting().subscribe(value=>{
            this.isRequesting = value;
        })
    }
}
//make loader visible
loaderService.setIsRequesting(true);
//make loader hide
loaderService.setIsRequesting(false);
您的根html模板:

<loading [isRunning]="isRequesting"></loading>
<router-outlet></router-outlet>
示例:


希望这会有所帮助。

您可以将加载程序添加到应用程序的根组件,并在根应用程序的模板中只添加一次选择器

完成后,您可以使用服务显示/隐藏正在加载的组件

您的服务将如下所示:

Import {DownloadComponent} from '../loading/carregando.component';
@Component({
   Selector: 'app-questions',
   TemplateUrl: './questions.component.html',
   StyleUrls: ['./questions.component.css'],
   EntryComponents: [LoadingComponent]
})
@Injectable()
export class LoaderService{
    //BehaviorSubject takes an initial value false in this case and 
    //provides the most recent value where ever it has been subscribed to.  
    isRequesting: BehaviorSubject<boolean> = new BehaviorSubject(false);
    public setIsRequesting (bool:boolean){
        this.isRequesting.next(bool);
    }
    pubilc getIsRequesting: BehaviorSubject<boolean>{
        return this.isRequesting;
    }
}
export class AppComponent{
    isRequesting: boolean = false;
    constructor(private loaderService: LoaderService)
    ngOnInit(){
        loaderService.getIsRequesting().subscribe(value=>{
            this.isRequesting = value;
        })
    }
}
//make loader visible
loaderService.setIsRequesting(true);
//make loader hide
loaderService.setIsRequesting(false);
您的根html模板:

<loading [isRunning]="isRequesting"></loading>
<router-outlet></router-outlet>
示例:


希望这有帮助。

嗨,你有完整的例子吗?因为我不能,我添加了一个极简主义的例子。嗨,你有一个完整的例子吗?因为我不可能,我添加了一个极简主义的例子。