想了解angularjs–带有null参数的$http.get没有访问WebAPI控制器的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于angularjsunknownprovider的相关
想了解angularjs – 带有null参数的$http.get没有访问Web API控制器的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于angularjs unknown provider的相关问题,此外,我们还将为您介绍关于$http 将 AngularJs 放入 WebApi 调用中,将对象的一个属性设为 null、$httpBackend(angularJS)中的URL参数、angulajs angularjs $timeout没有延迟参数的原因、Angular 2 HTTP GET与TypeScript错误http.get(…).map不是一个函数在[null]的新知识。
本文目录一览:- angularjs – 带有null参数的$http.get没有访问Web API控制器(angularjs unknown provider)
- $http 将 AngularJs 放入 WebApi 调用中,将对象的一个属性设为 null
- $httpBackend(angularJS)中的URL参数
- angulajs angularjs $timeout没有延迟参数的原因
- Angular 2 HTTP GET与TypeScript错误http.get(…).map不是一个函数在[null]
angularjs – 带有null参数的$http.get没有访问Web API控制器(angularjs unknown provider)
$http.get(BasePath + '/api/documentapi/GetDocuments/',{ params: { PrimaryID: ID1,AlternateID: ID2,} }).then( ...
在我的情况下,PrimaryID或AlternateID将具有该值.因此,其中一个将始终为null.
我的Web api方法是
public DocumentsDto[] GetDocuments(decimal? PrimaryID,decimal? AlternateID) { ...
当其中一个值为null时,$http.get生成的url如下所示:
http://BaseServerPath/api/documentapi/GetDocuments/?PrimaryID=1688
要么
http://BaseServerPath/api/documentapi/GetDocuments/?AlternateID=154
这没有达到我的Web API方法.
但是,如果我使用
http://BaseServerPath/api/documentapi/GetDocuments/?PrimaryID=1688&AlternateID=null
有用.我可以在我的参数中将值硬编码为null,但是我想知道是否有任何正确的方法来实现这一点.
谢谢,
山姆
public string GetFindBooks(string author="",string title="",string isbn="",string somethingelse="",DateTime? date= null) { // ... }
在我的情况下,它将是
public DocumentsDto[] GetDocuments(decimal? PrimaryID = null,decimal? AlternateID = null) { ...
$http 将 AngularJs 放入 WebApi 调用中,将对象的一个属性设为 null
如何解决$http 将 AngularJs 放入 WebApi 调用中,将对象的一个属性设为 null?
我是 AngularJS 的新手。我创建了一个对话框来更新一个类对象。除 Id 属性外,所有其他属性都正确。
类:
[Serializable]
public class Payment
{
public virtual string Id { get; set; }
public virtual string PaymentId{ get; set; }
public virtual string FeeType { get; set; }
public virtual string Payer { get; set; }
public virtual string Receiver { get; set; }
}
AngularJs 服务
var updatePaymentData = function (payment) {
return serviceBase
.put(serviceBase.applicationserviceWebApiUrl + "api/ExportMaintenance/UpdatePayment",payment)
.then(function (result) {
loggingManager.logSuccessMessage("payment " + payment.feeType + " has been updated.");
return result;
});
};
ServiceBase 放置代码:
function httpRequestWithTimeOut(req,timeOut) {
var timeOutLength = timeOut;
var hasTimeOut = false;
var timeout = $q.defer();
var deferred = $q.defer();
setTimeout(function () {
hasTimeOut = true;
timeout.resolve();
},(1000 * timeOutLength));
// Add the default timeout promise.
req.timeout = timeout.promise;
$http(req)
.success(function (result) {
deferred.resolve(result);
})
.error(function (error) {
if (hasTimeOut) {
deferred.reject({
error: "timeout",message: "The request took too long and has time out."
});
} else {
deferred.reject(error);
}
});
return deferred.promise;
}
var put = function (location,data) {
var req = {
method: "put",url: location,data: data,cache: false
};
return httpRequest(req);
};
function httpRequest(req) {
// Default time out to 180 seconds.
return httpRequestWithTimeOut(req,180);
}
WEB API 相关代码:
// PUT api/ExportMaintenance/UpdatePayment
[HttpPut,ValidateModel]
[WebApiClaimsAuthorization(Type = "ExportMaintenance",Value = "CanUpdate",Description = "Can update Export Maintenance")]
public HttpResponseMessage UpdatePayment(Payment paymentData)
{
var responseMessage = new ResponseMessage(Request,paymentData);
_paymentBusinessLogic.UpdatePaymentData(paymentData,User,responseMessage);
return responseMessage.SetHttpResponseMessage(paymentData);
}
放入请求中的数据对象图像
它们是类中的更多属性我在写入时删除了它们所有属性都显示在数据对象图像中 从网络选项卡请求负载
在 WebAPI 中,我将 payment.Id 设为 null,但是当我在 Chrome 调试工具中看到 paymentData 在控制器和服务中具有 Id 值时。
我无法理解为什么 Id 为空。请至少帮我分析一下这个问题。
谢谢, 纳加里。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
$httpBackend(angularJS)中的URL参数
$httpBackend.whenGET('/api/v1/users/{userId}').respond(function (method,url,data) { // somehow read {userId} and act differently depending on what the value is return [200]; });
拥有这个功能真的可以很容易地创建一个功能相当的模拟API(更容易开发前端应用程序而无需运行整个后端).
解决方法
angulajs angularjs $timeout没有延迟参数的原因
$timeout(function () { $scope.my = 1; });
而不是简单
$scope.my = 1;
调用$ timeout没有延迟的目的是什么?
Angular 2 HTTP GET与TypeScript错误http.get(…).map不是一个函数在[null]
我只想获取一个JSON列表,并在视图中显示它。
服务类
import {Injectable} from "angular2/core"; import {Hall} from "./hall"; import {Http} from "angular2/http"; @Injectable() export class HallService { public http:Http; public static PATH:string = 'app/backend/' constructor(http:Http) { this.http=http; } getHalls() { return this.http.get(HallService.PATH + 'hall.json').map((res:Response) => res.json()); } }
在HallListComponent中,我从服务调用getHalls方法:
export class HallListComponent implements OnInit { public halls:Hall[]; public _selectedId:number; constructor(private _router:Router,private _routeParams:RouteParams,private _service:HallService) { this._selectedId = +_routeParams.get('id'); } ngOnInit() { this._service.getHalls().subscribe((halls:Hall[])=>{ this.halls=halls; }); } }
但是,我有一个例外:
TypeError: this.http.get(…).map is not a function in [null]
hall-center.component
import {Component} from "angular2/core"; import {RouterOutlet} from "angular2/router"; import {HallService} from "./hall.service"; import {RouteConfig} from "angular2/router"; import {HallListComponent} from "./hall-list.component"; import {HallDetailComponent} from "./hall-detail.component"; @Component({ template:` <h2>my app</h2> <router-outlet></router-outlet> `,directives: [RouterOutlet],providers: [HallService] }) @RouteConfig([ {path: '/',name: 'HallCenter',component:HallListComponent,useAsDefault:true},{path: '/hall-list',name: 'HallList',component:HallListComponent} ]) export class HallCenterComponent{}
app.component
import {Component} from 'angular2/core'; import {ROUTER_DIRECTIVES} from "angular2/router"; import {RouteConfig} from "angular2/router"; import {HallCenterComponent} from "./hall/hall-center.component"; @Component({ selector: 'my-app',template: ` <h1>Examenopdracht Factory</h1> <a [routerLink]="['HallCenter']">Hall overview</a> <router-outlet></router-outlet> `,directives: [ROUTER_DIRECTIVES] }) @RouteConfig([ {path: '/hall-center/...',name:'HallCenter',component:HallCenterComponent,useAsDefault:true} ]) export class AppComponent { }
tsconfig.json
{ "compilerOptions": { "target": "ES5","module": "system","moduleResolution": "node","sourceMap": true,"emitDecoratorMetadata": true,"experimentalDecorators": true,"removeComments": false,"noImplicitAny": false },"exclude": [ "node_modules" ] }
对不起,长的帖子…
import 'rxjs/add/operator/map'
或者更一般地说,如果你想有更多的方法观察:
import 'rxjs/Rx';
有关详细信息,请参阅this issue。
今天关于angularjs – 带有null参数的$http.get没有访问Web API控制器和angularjs unknown provider的分享就到这里,希望大家有所收获,若想了解更多关于$http 将 AngularJs 放入 WebApi 调用中,将对象的一个属性设为 null、$httpBackend(angularJS)中的URL参数、angulajs angularjs $timeout没有延迟参数的原因、Angular 2 HTTP GET与TypeScript错误http.get(…).map不是一个函数在[null]等相关知识,可以在本站进行查询。
本文标签: