我用一个组件创建了简单的angular 2应用并注入了服务 返回静态数据但应用程序无法正常工作并引发控制台错误
@Injectable()
export class UsersServices{
getUsers():User[] {
return [{name:'Ahmed'},{name:'Ali'}];
}
}
@Component({
selector:'users',
templateUrl:'./users.component.html',
providers:[UsersServices]
})
export class UsersComponent implements OnInit{
Users:User[];
constructor(private userService: UsersServices) { }
ngOnInit(){
this.Users= this.userService.getUsers();
}
}