Angular Controller中的客户端功能实现
function updateData() {
dataService.put("/api/Product/" +
vm.product.ProductId,
vm.product)
.then(function (result) {
// Update product object
vm.product = result.data;
// Get index of this product
var index = vm.products.map(function (p)
{ return p.ProductId; })
.indexOf(vm.product.ProductId);
// Update product in array
vm.products[index] = vm.product;
setUIState(pageMode.LIST);
}, function (error) {
handleException(error);
});
}
API实施
[HttpPut()]
public IHttpActionResult Put(int id,
Product product) {
IHttpActionResult ret = null;
PTCViewModel vm = new PTCViewModel();
vm.Entity = product;
vm.PageMode = PageConstants.EDIT;
vm.Save();
if (vm.IsValid) {
ret = Ok(product);
}
else if (vm.Messages.Count > 0) {
ret = BadRequest(ConvertToModelState(vm.Messages));
}
else {
ret = NotFound();
}
return ret;
}
[HttpDelete()]
public IHttpActionResult Delete(int id) {
IHttpActionResult ret = null;
PTCViewModel vm = new PTCViewModel();
// Get the product
vm.Entity = vm.Get(id);
// Did we find the product?
if (vm.Entity.ProductId > 0) {
// Delete the product
vm.Delete(id);
ret = Ok(true);
}
else {
ret = NotFound();
}
return ret;
}
答案 0 :(得分:0)
尝试将api端点的整个网址放在此处:
#define IDX(_M,_i,_j) (_M)[(_i) * N + (_j)]
#define U(_i, _j) IDX(uL, _i, _j)
__kernel void jacobi(__global VALUE* u, __global VALUE* f, __global VALUE* tmp, VALUE factor) {
int i = get_global_id(0);
int j = get_global_id(1);
int iL = get_local_id(0);
int jL = get_local_id(1);
__local VALUE uL[(N+2)*(N+2)];
__local VALUE fL[(N+2)*(N+2)];
IDX(uL, iL, jL) = IDX(u, i, j);
IDX(fL, iL, jL) = IDX(f, i, j);
barrier(CLK_LOCAL_MEM_FENCE);
IDX(tmp, i, j) = (VALUE)0.25 * ( U(iL-1, jL) + U(iL, jL-1) + U(iL, jL+1) + U(iL+1, jL) - factor * IDX(fL, iL, jL));
}
类似的东西:
"/api/Product/"
答案 1 :(得分:0)
问题是使用新版本的Angular,只要Angular版本是1.x而不是2.x,所有API方法调用都是成功的,这是因为在Angular 2中进行PUT和DELETE调用的语法.x是不同的,这解释了为什么这些端点返回404 Not Found错误。