小编Fer*_*rie的帖子

如何在角度js中进行同步http请求

如何在AngularJS中阻止http请求,以便我可以在下一行使用$ http响应?

在下面的示例中,$httpobject不会将结果返回到下一行,以便我可以将此结果传递fullcalender()给JavaScript库,因为它$scope.data返回空值.

这是示例代码:

$http.get('URL').success(function(data){
    $scope.data = data;
});

$.fullCalender({
    data: $scope.data
});
Run Code Online (Sandbox Code Playgroud)

angularjs

19
推荐指数
1
解决办法
5万
查看次数

未捕获(承诺):错误:StaticInjectorError(AppModule)[employeService - > Http]:

当我在我的服务的构造函数中使用Http时,我面临上述错误.

员工服务代码

import { Component } from '@angular/core'
import { Injectable } from '@angular/core'
import { HttpModule } from '@angular/http';
import { Http, Response } from '@angular/http';
import { Observable } from 'rxjs/observable';
import 'rxjs/add/operator/map';

@Injectable()
export class employeService {
    constructor(public http: Http){ }

    getEmployeename(): Observable<string> {
        return this.http.get('http://localhost:53656/api/values/Getdata').map((resp: Response) =>
            resp.json()
        );
    }
}
Run Code Online (Sandbox Code Playgroud)

注意我在员工组件内部直接调用我的服务(不是来自app.module.ts文件)

员工组件代码

import { Component, OnInit } from '@angular/core';
import { employeService } from './Service/service';

@Component({  
    templateUrl: './app.employee.html',
    providers: [employeService]
})
export class EmployeeComponent implements …
Run Code Online (Sandbox Code Playgroud)

angular

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

标签 统计

angular ×1

angularjs ×1