我试图在组件呈现之前从我的API加载一个事件.目前我正在使用我的API服务,我从组件的ngOnInit函数调用它.
我的EventRegister
组件:
import {Component, OnInit, ElementRef} from "angular2/core";
import {ApiService} from "../../services/api.service";
import {EventModel} from '../../models/EventModel';
import {Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, RouteConfig, RouteParams, RouterLink} from 'angular2/router';
import {FORM_PROVIDERS, FORM_DIRECTIVES, Control} from 'angular2/common';
@Component({
selector: "register",
templateUrl: "/events/register"
// provider array is added in parent component
})
export class EventRegister implements OnInit {
eventId: string;
ev: EventModel;
constructor(private _apiService: ApiService,
params: RouteParams) {
this.eventId = params.get('id');
}
fetchEvent(): void {
this._apiService.get.event(this.eventId).then(event => {
this.ev = event;
console.log(event); // Has a …
Run Code Online (Sandbox Code Playgroud) 我有以下代码来上传文件。
var client = new dio.Dio();
await client.put(
url,
data: formData,
options: dio.Options(
headers: headers,
),
onSendProgress: (int sent, int total) {
final progress = sent / total;
print('progress: $progress ($sent/$total)');
},
);
Run Code Online (Sandbox Code Playgroud)
上传文件工作正常。问题是,我有一个视图,它有一个圆形进度条,指示onSendProgress
触发时的上传进度。当我上传一个 ~10MB 的文件时,进度条会在一秒钟内从 0% 跳到 100%,然后在继续执行其余代码之前等待几秒钟(取决于文件大小)。这对我来说似乎很奇怪,因为我希望进度条会逐渐增加进度。
您可以在下面找到我的示例中的打印输出,其中包含一个 ~10MB 的文件。
flutter: progress: 0.000003035281907563734 (29/9554302)
flutter: progress: 0.000013187776563897604 (126/9554302)
flutter: progress: 0.999996546058519 (9554269/9554302)
flutter: progress: 0.9999967553883057 (9554271/9554302)
flutter: progress: 1.0 (9554302/9554302)
Run Code Online (Sandbox Code Playgroud)
这是一个较小的文件,但具有相同数量的回调。
flutter: progress: 0.00001847214941293598 (29/1569931)
flutter: progress: 0.00008025830434585978 (126/1569931)
flutter: progress: 0.9999789799679094 (1569898/1569931)
flutter: progress: 0.9999802539092483 …
Run Code Online (Sandbox Code Playgroud) 我正在尝试Patch
使用HttpClient
in dotnet核心创建一个请求.我找到了其他方法,
using (var client = new HttpClient())
{
client.GetAsync("/posts");
client.PostAsync("/posts", ...);
client.PutAsync("/posts", ...);
client.DeleteAsync("/posts");
}
Run Code Online (Sandbox Code Playgroud)
但似乎无法找到Patch
选项.可以Patch
用HttpClient
?做请求吗?如果是这样,有人能告诉我一个如何做的例子吗?
我在 FutureBuilder 启动两次时遇到问题。首先它正确获取数据,返回我的 StartScreen,然后几秒钟后,StartScreen 重建,我注意到 FutureBuilder 再次触发。
这是我的代码,它非常简单,所以我想知道可能是什么问题?!?
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
FirebaseUser user;
@override
void initState() {
// TODO: implement initState
super.initState();
getNewestlocation();
}
@override
void dispose() {
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'APP',
theme: buildTheme(),
home: FutureBuilder<FirebaseUser>(
future: Provider.of<AuthService>(context).getUser(),
builder: (context, AsyncSnapshot<FirebaseUser> snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.error != null) {
print('error');
return Text(snapshot.error.toString());
}
user …
Run Code Online (Sandbox Code Playgroud) 我已经成功地序列化API响应到snake_case
在我使用以下命名约定Startup.cs
。通过这种方式,它将我的 DTO 返回为蛇形 JSON。
services
.AddMvc()
.AddJsonOptions(x =>
{
x.SerializerSettings.ContractResolver = new DefaultContractResolver
{
NamingStrategy = new SnakeCaseNamingStrategy()
};
});
Run Code Online (Sandbox Code Playgroud)
这是我想要的一半。但是当我发布蛇形 JSON 时,请参见下面的示例,它不会将值绑定到 api 上的 DTO。例如UserProfile
数组和CreatedOn
,ModifiedOn
没有得到任何值。
{
"user_profiles": [
{
"id": 1,
"created_on": "2017-02-08T19:54:59.370Z",
"modified_on": "2017-02-18T14:10:42.248Z",
"email": "my@email.com",
"username": "my_username"
}
],
"id": 1,
"created_on": "2017-02-08T19:50:31.690Z",
"modified_on": 2017-02-08T19:50:31.690Z,
"name": "My Company Name"
}
Run Code Online (Sandbox Code Playgroud)
设置它以便API在发送到api时处理蛇形JSON并在从api请求时将其作为蛇形发送的正确方法是什么?
我的 DTO
public class CompanyDto
{
public int Id { get; set; …
Run Code Online (Sandbox Code Playgroud) 我想测试一个函数,它通过集成测试将文件附加到RavenDB数据库中的文档.为此,我需要一个实例IFormFile
.
显然,我无法从接口实例化,所以我试图实例化一个FormFile
从IFormFile
接口继承的实例.
using (var stream = File.OpenRead("placeholder.pdf"))
{
var file = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name))
{
ContentType = "application.pdf"
};
}
Run Code Online (Sandbox Code Playgroud)
但是这会引发以下错误:
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.AspNetCore.Http.Internal.FormFile.set_ContentType(String value)
Run Code Online (Sandbox Code Playgroud)
当我ContentType = "application.pdf"
从代码中删除它时,它允许我实例化一个新实例,但没有ContentType
.
如何FormFile
使用ContentType
和不使用Moq
框架实例化实例?
我试图通过安全的api请求图像.目前我已经完成了以下工作(请参阅下面我使用的所有资源.
import { AssetsService } from '../../services/AssetsService';
import { Component } from '@angular/core';
@Component({
templateUrl: 'home.html',
})
export class HomePage {
public img;
constructor(
public assets_service: AssetsService
) { }
public async ionViewDidEnter() {
this.img = await this.assets_service.picture_request('test.png');
}
}
Run Code Online (Sandbox Code Playgroud)
我的看法
<img [src]="img | safe" />
Run Code Online (Sandbox Code Playgroud)
现在我已经看到了看起来很有希望的异步管道.正如您可能已经猜到的那样,我真的不想对我想通过上面使用的api请求的每个图像使用viewmodel属性.
我想picture_request
直接从html视图使用异步调用.这将节省我在viewmodel中的所有管道.从我所读到的东西,像这样的东西应该工作,但只有它不可悲.
<img [src]="assets_service.picture_request('test.png') | async | safe" />
Run Code Online (Sandbox Code Playgroud)
我不确定我是使用async pipe
正确还是使用正确的方法.如果我不是我的方法应该是什么?任何帮助表示赞赏.仅供参考:我使用角度2与离子2结合使用.
我用过的其他资源:
我的安全管
import { Pipe, PipeTransform } from '@angular/core';
import { DomSanitizer } from '@angular/platform-browser';
@Pipe({ name: …
Run Code Online (Sandbox Code Playgroud) 当我没有display: flex
在.container
减小容器大小时,文本会正确截断。
但是绿色块和文本不再彼此相邻,因为容器没有display: flex
. 当我将其添加到容器中时,绿色块和文本正确对齐,但文本不再被截断(省略号丢失)。
如何使用 Flex 确保块和文本对齐,而且文本在动态宽度容器中被省略号截断?
body {
padding: 20px;
}
.container {
display: flex;
}
.block {
width: 25px;
height: 25px;
padding: 10px;
background-color: yellowgreen;
display: flex;
align-items: center;
justify-content: center;
margin-right: 20px
}
.text {
display: flex;
}
.truncate {
flex: 1;
min-width: 0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
font-size: 20pt;
}
Run Code Online (Sandbox Code Playgroud)
<div class="container">
<div class="block">B</div>
<div class="text">
<div class="truncate">
3. This is a long string that is …
Run Code Online (Sandbox Code Playgroud)我想从CheckoutController更改OpcSaveBilling操作的一些代码中的一些代码.我不想改变NopCommerce的核心代码,所以我需要尝试使用我自己的自定义代码覆盖代码.
我读过这篇文章是为了让我开始http://www.pronopcommerce.com/overriding-intercepting-nopcommerce-controllers-and-actions.根据我的阅读,您可以在执行操作之前和执行操作之后执行自己的代码.但我没有得到的是文章开放的部分(需要执行的实际代码).
我基本上想要的是原始代码的相同功能,但有一些自定义调整.我在OnePageCheckout视图中添加了一个复选框,根据该复选框,它需要在结帐时跳过输入送货地址部分.(使用送货地址的帐单邮寄地址)
我已经在核心代码和这项工作中添加了代码并跳过了这一步(注意:我知道我仍然需要手动添加帐单地址作为送货地址)但是就像我说我不想改变代码NopCommerce的核心,但覆盖它.
如果我的问题不可理解,您需要更多代码或解释,我很乐意提供更多.如果我这样做的方式不适合我想要的,如果你告诉我,我将不胜感激!
我的代码:
Action Filter类:
using Nop.Web.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
namespace Nop.Plugin.Misc.MyProject.ActionFilters
{
class ShippingAddressOverideActionFilter : ActionFilterAttribute, IFilterProvider
{
public IEnumerable<Filter> GetFilters(ControllerContext controllerContext, ActionDescriptor actionDescriptor)
{
if (controllerContext.Controller is CheckoutController && actionDescriptor.ActionName.Equals("OpcSaveBilling", StringComparison.InvariantCultureIgnoreCase))
{
return new List<Filter>() { new Filter(this, FilterScope.Action, 0) };
}
return new List<Filter>();
}
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
// What do I put in here? So that I have the …
Run Code Online (Sandbox Code Playgroud) $type
当我保存动态类型值时,有没有办法防止添加属性?
当我保存这个时:
new Activity {
Name = "FormFieldDeleted",
Body = new {
MyDeletedFormField(),
MyCompleteForm()
}
}
Run Code Online (Sandbox Code Playgroud)
我明白了
<>f__AnonymousType1`2[[MyProject.Domains.Forms.Models.FormField, MyProject.Domains.Forms],[MyProject.Domains.Forms.Entities.FormRegistration, MyProject.Domains.Forms]], MyProject.Api.Forms
Run Code Online (Sandbox Code Playgroud)
但是当我尝试获取这个保存的实体时,它会崩溃并出现以下异常。我知道它缺少项目引用,但我真的不想添加该引用(我不想从控制台应用程序引用 API)。我最好只是阻止$type
财产。
/usr/local/share/dotnet/dotnet path/MyProject/MyProject/src/MyProject.Tasks.MapActivities/bin/Debug/netcoreapp3.1/MyProject.Tasks.MapActivities.dll
Unhandled exception. System.InvalidOperationException: Could not convert document 31317d58-db9e-4f60-8dee-b8593f3e06c0 to entity of type MyProject.Domains.Core.Entities.Activity
---> Newtonsoft.Json.JsonSerializationException: Error resolving type specified in JSON '<>f__AnonymousType1`2[[MyProject.Domains.Forms.Models.FormField, MyProject.Domains.Forms],[MyProject.Domains.Forms.Entities.FormRegistration, MyProject.Domains.Forms]], MyProject.Api.Forms'. Path 'Body.$type'.
---> Newtonsoft.Json.JsonSerializationException: Could not load assembly 'MyProject.Api.Forms'
....
Run Code Online (Sandbox Code Playgroud) c# ×3
.net-core ×2
angular ×2
flutter ×2
asp.net-mvc ×1
asynchronous ×1
blob ×1
css ×1
dart ×1
dio ×1
dynamic ×1
ellipsis ×1
file-upload ×1
flexbox ×1
flutter-http ×1
html ×1
http-patch ×1
iformfile ×1
ionic2 ×1
javascript ×1
json ×1
nopcommerce ×1
overflow ×1
ravendb ×1
ravendb4 ×1
typescript ×1