小编Pau*_*l B的帖子

Angular 6 - 通过服务将消息传递到组件到消息组件

我正在尝试如何传递消息app.component.ts来显示messageComponent.ts

app.component.html我添加<app-messagecomponent></app-messagecomponent>

添加它什么都没有显示的那一刻.

我在服务中也有一个方法:

message.service.ts

message(message) {
    return message;
}
Run Code Online (Sandbox Code Playgroud)

所以我想通过消息服务从其他组件传递消息,以便在app-messagecomponent.html中显示

例如,来自app.component.ts:

sendMessageToService() {
    this.myservice.message('my Message to be displayed in the messageComponent');
}
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

typescript angular angular6

13
推荐指数
1
解决办法
2万
查看次数

Angular 6 - run方法每10秒服务一次

我有这个服务使用HttpClient来获取一些数据:

checkData() {
    return this.http.get('my url');
}
Run Code Online (Sandbox Code Playgroud)

我在脚注组件上调用它并显示结果:

ngOnInit() {
    this.myservice.checkdata().subscribe( result => { this.statustext = result } );
}
Run Code Online (Sandbox Code Playgroud)

这有效,但我需要每10秒运行一次这样的方法,因此它是最新的.

我怎样才能做到这一点?

rxjs typescript angular angular6

9
推荐指数
2
解决办法
2万
查看次数

Angular 6 - 使用*ngFor显示数据的问题(数据未显示)

我有一些看起来像这样的数据:

在此输入图像描述

在我身上app.component.html我有这个:

<ul>
  <li *ngFor="let data of myData">{{data.id}}</li>
</ul>
Run Code Online (Sandbox Code Playgroud)

当我运行它时它显示列表但没有任何值,所以我只是从中得到了很多点 <li>

在我的app.component.ts身上:

myData;
Run Code Online (Sandbox Code Playgroud)

然后:

this.myData = obj; // Obj contains the data
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

typescript angular angular6

3
推荐指数
1
解决办法
2万
查看次数

Angular 6-将数据传递到类变量时变得不确定

我有一个服务,在构造函数中,我正在运行一种方法来获取一些数据。我可以看到数据,然后将其传递给预定义的变量。

像这样:

export class SentinelService {

  configuration;

  constructor() {


    this.electronService.ipcRenderer.on('config' , function(event , data) {

      this.configuration = data; // pass the data to configuration variable

      console.log(this.configuration.name); // Check it ... I can see the value here


    });

  }


  myMethod() {

    // Try it here
    console.log(this.configuration.name); // I get Undefined

  };


  ...
Run Code Online (Sandbox Code Playgroud)

尽管我已经将值分配给“ configuration”变量,并且可以看到它是从构造函数内部的方法传递的,但是当我在另一个方法上尝试相同的操作时,却无法定义。

我怎样才能解决这个问题?

typescript angular angular6

2
推荐指数
1
解决办法
3062
查看次数

标签 统计

angular ×4

angular6 ×4

typescript ×4

rxjs ×1