相关疑难解决方法(0)

使用带有角度2的http rest apis

所以,我正在通过打字稿在他们的网站上关注角度2指南,并且我陷入了http api集成.我正在尝试创建一个简单的应用程序,可以通过soundcloud api搜索一首歌,但是我很难实现和理解如何开始,而且在线资源以很多不同的方式完成它(我相信快速的角度2语法更改)早些时候).

所以目前我的项目看起来像这样

app
  components
    home
      home.component.ts
      ...
    search
      search.component.ts
      ...
    app.ts
    ...
  services
    soundcloud.ts
  bootstrap.ts
index.html
Run Code Online (Sandbox Code Playgroud)

在示例中没有任何花哨的东西,主要文件将是

app.ts

import {Component, View} from 'angular2/core';
import {RouteConfig, ROUTER_DIRECTIVES} from 'angular2/router';

import {HomeComponent} from './home/home.component';
import {SearchComponent} from './search/search.component';

@Component({
    selector: 'app',
    templateUrl: 'app/components/app.html',
    directives: [ROUTER_DIRECTIVES]
})

@RouteConfig([
  {path: '/home', name: 'Home', component: HomeComponent, useAsDefault: true},
  {path: '/search', name: 'Search', component: SearchComponent}
])

export class App { }
Run Code Online (Sandbox Code Playgroud)

bootstrap.ts

    import {App}     from './components/app';
import {bootstrap}        from 'angular2/platform/browser';
import {ROUTER_PROVIDERS} from 'angular2/router'; …
Run Code Online (Sandbox Code Playgroud)

javascript http angular

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

Angular2 - 无法在嵌套调用中读取未定义的属性"subscribe"

我已经看了很多资源,包括这个,这个这个,但是我还没有达到预期的效果.

我要做的就是验证用户身份(使用firebase)然后进行身份验证后,加载他们的配置文件并将其存储在变量中,userProfile然后再加载下一页Dashboard:

我的登录服务:

public signinUser(user: User) {
    this.af.auth.login({
        email: user.email,
        password: user.password
    },
        {
            provider: AuthProviders.Password,
            method: AuthMethods.Password
        }

    )
        .then(                
        success => {
            console.log('Authenticated');
            this.getProfile().subscribe( // PROBLEM is here
                profile => {
                    console.log(profile);
                    console.log('Profile Loaded');
                    this.router.navigate(['/dashboard']);
                }
            )               
        }
        )
        .catch(function (error) {
            ...
            console.log('ERROR SIGNING USER IN');
        }
Run Code Online (Sandbox Code Playgroud)

我的getProfile()方法:

public getProfile(): Observable<any> {            
        return this.af.database.object('/profiles/' + this.user.uid)
        .flatMap(
            profile => {
                console.log('inside success');
                console.log(profile);
                this.userProfile = <User>profile;                    
                console.log('getProfile …
Run Code Online (Sandbox Code Playgroud)

asynchronous callback chaining observable angular

10
推荐指数
1
解决办法
4万
查看次数