我试图在点击搜索按钮时显示详细视图中的值。下面是我的listView.html代码。
<span class="link" ng-click="vm.openDetailsView(firmware.id)"><i class="fa fa-search"></i> View</span>
和各自的listView typescript文件,其中我传递firmware.id作为参数,并重定向到详细视图页面。
openDetailsView(fwId: string) {
this.$window.location.href = `#/firmwareCatalog/firmware/${fwId}`;
}
我的detailView.ts文件如下所示:
export class FirmwareController {
isLoading: boolean = false;
private logger: ILogger;
private firmwareId: any;
private firmware: any;
constructor(private $stateParams: any,
logger: LoggerService,
private firmwareService: FirmwareService,
private modalService: ModalService,
private $window: any) {
this.reset();
this.firmwareId = $stateParams.firmwareId;
this.loadFirmwareDetails();
this.logger = logger.getLogger('firmware');
}
loadFirmwareDetails() {
this.isLoading = true;
this.firmwareService.getFirmware(this.firmwareId)
.then((fw: any) => {
this.firmware = fw;
})
.finally(() => {
this.isLoading = false;
});
}
}
相应的DetailView.service.ts文件:
private routes = {
getFirmwareById: '/firmwares/{:firmwareId}',
};
getFirmware(id: any): any {
const uri = this.routes.getFirmwareById.replace('{:firmwareId}', id);
return this.restService
.get(uri, null, true)
.then((response: any) => {
if (response.data) {
return response.data;
}
})
.catch((response: any) => {
return this.$q.reject(response);
});
}
下面是我的Controller.cs:
[Route("firmwares/{firmwareId}")]
[HttpGet]
public Firmware GetById(int firmwareId)
{
this.logService.Debug($"Entering GET api/firmwares/{firmwareId}");
var connectedUser = this.permissionService.GetConnectedUser();
this.permissionService.CheckRolePermission(connectedUser.Role, PermissionConstant.ViewFirmwares);
var result = Firmware.From(this.etpService.GetFirmwarefromEtpById(firmwareId));
return result;
}
下面是我的模型类:
public class Firmware
{
[JsonProperty("id")]
public string Id { get; set; }
[JsonProperty("deviceType")]
public string DeviceType { get; set; }
[JsonProperty("filename")]
public string Filename { get; set; }
[JsonProperty("size")]
public int Size { get; set; }
[JsonProperty("uploadDate")]
public DateTime UploadDate { get; set; }
[JsonProperty("url")]
public string Url { get; set; }
[JsonProperty("version")]
public string Version { get; set; }
public static EtpFirmwareModel From(EtpFirmwareModel model)
=> model == null ? null : new EtpFirmwareModel
{
Id = model.Id,
DeviceType = model.DeviceType,
Filename = model.Filename,
Size = model.Size,
UploadDate = model.UploadDate,
Url = model.Url,
Version = model.Version
};
}
我使用GET动词从API获取数据。并且无法命中到我的Controller.cs文件这里是错误的详细信息:
[restService] {"Message":"The request is invalid."}
我是新的Angular ,请帮助我解决这个问题。先谢谢你了。
1条答案
按热度按时间6psbrbz91#
错误消息“请求无效”意味着路径不正确,写入
#/firmwareCatalog/firmware/${fwId}
请交叉检查控制器路径。我可以看到控制器中提到的路径是[Route(“firmwares/{firmwareId}”)]。所以路径应该是固件而不是固件。
你能试试下面的路径吗
$window.location.href =
/firmwares/${fwId}
;