离子/角度/打字稿非常新。我试图从本地rails服务器获取json。我一直遇到的错误是"找不到姓名' MessageService'"当提供离子/ cordova时。我的message-service.ts文件看起来像这样
import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
@Injectable()
export class MessageService {
constructor(private http: Http) {}
getMessages() {
let messages = this.http.get(`http://localhost:3000/conversations/1/messages`);
return messages;
}
}
这可能是一个提示,sublime突出显示MessageService和提及"对装饰器的实验性支持是一个在将来的版本中可能会发生变化的功能。"
我的home.ts代码如下
import { Component } from '@angular/core';
import { MessageService } from '../../services/message-service';
import { NavController } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html',
providers: [ MessageService ]
})
export class HomePage {
public foundMessages;
constructor(private message: MessageService) {
}
getMessages() {
this.message.getMessages().subscribe(
data => {
this.foundMessages = data.json();
},
err => console.log(err),
() => console.log('get Messages completed')
)
}
}
对此非常陌生。任何帮助表示赞赏