我正在尝试从输入事件创建一个Observable.我已经尝试了几乎所有东西,我无法导入"fromEvent".这是我的代码.我使用角度6.0.1和RXJS 6.1.0
错误TS2339:类型'typeof Observable'上不存在属性'fromEvent'.
import { Directive, EventEmitter, Input, Output, ElementRef, ViewChild, AfterViewInit } from '@angular/core';
import { NgControl } from '@angular/forms';
import { distinctUntilChanged } from 'rxjs/internal/operators/distinctUntilChanged';
import { debounceTime } from 'rxjs/internal/operators/debounceTime';
import { map } from 'rxjs/internal/operators/map';
import { filter } from 'rxjs/internal/operators/filter';
import { Observable } from 'rxjs/internal/Observable';
//import 'rxjs/internal/observable/fromEvent';
//import 'rxjs/add/observable/fromEvent';
@Directive({
selector: '[ngModel][debounceTime]'
})
export class InputDebounceDirective implements AfterViewInit {
@Output()
public onDebounce = new EventEmitter<any>();
@Input('debounceTime')
public debounceTime: number = 1500;
constructor(private elementRef: …Run Code Online (Sandbox Code Playgroud) 请注意,分页/排序无法正常工作.分页不显示它显示的元素数量,并且排序不起作用,但是如果删除html文件中的行*ngIf ="dataSource?.filteredData.length> 0",则错误是固定的.如果您使用过滤,它可以工作,但它不会显示过滤器数量
检查示例.
https://stackblitz.com/edit/angular-wqkekh-nm3pn2?file=app/table-pagination-example.html
我想创建一个自定义 Authorize 属性,以便能够在失败时发送个性化响应。有很多例子,但我找不到我要找的东西。注册保单时,我添加了“索赔”。是否可以在自定义属性中访问该注册声明而无需通过参数传递声明?或者是否有可能知道索赔检查是否发生,如果没有,返回个性化回复?谢谢!
public static void AddCustomAuthorization(this IServiceCollection serviceCollection)
{
serviceCollection.AddAuthorization(x =>
{
x.AddPolicy(UserPolicy.Read,
currentPolicy => currentPolicy.RequireClaim(UserClaims.Read));
});
}
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)]
public class CustomAuthorizeAttribute : AuthorizeAttribute, IAuthorizationFilter
{
public void OnAuthorization(AuthorizationFilterContext authorizationFilterContext)
{
if (authorizationFilterContext.HttpContext.User.Identity.IsAuthenticated)
{
if (!authorizationFilterContext.HttpContext.User.HasClaim(x => x.Value == "CLAIM_NAME")) // ACCESS TO REGISTER CLAIM => currentPolicy => currentPolicy.RequireClaim(UserClaims.Read)
{
authorizationFilterContext.Result = new ObjectResult(new ApiResponse(HttpStatusCode.Unauthorized));
}
}
}
}
[HttpGet]
[CustomAuthorizeAttribute(Policy = UserPolicy.Read)]
public async Task<IEnumerable<UserDTO>> Get()
{
return ...
}
Run Code Online (Sandbox Code Playgroud) 我想创建一个自定义通用验证器,它将通过参数传递正则表达式的模式和要检查的属性(表单组)的名称。我有以下代码
UserName: new FormControl('',
[
Validators.required,
Validators.minLength(8),
this.OnlyNumbersAndLetterValidator(/^[a-zA-Z0-9]+$/, "UserName")
]
)
OnlyNumbersAndLetterValidator(regexPattern: RegExp, propertyName: string): ValidatorFn {
return (currentControl: AbstractControl): { [key: string]: any } => {
if (!regexPattern.test(currentControl.value)) {
return { propertyName: true }
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是当表达式无效时,返回"{propertyName: true}",而不是"{UserName: true}",有什么问题?
我在“combineLatest”中有 4 个可观察值。我需要的是,如果可观察值 1、3 或 4 发出一个值,则可观察值 2 会重置其值。这是可能的?谢谢
combineLatest($1, $2, $3, $4).subscribe(([a, b, c, d]) => CALL_HTTP_WITH_PARAMETERS(a, b, c, d))
Run Code Online (Sandbox Code Playgroud)
示例(第一个值)
$1 = name,asc
$2 = 2
$3 = bla bla
$4 = bla bla
CALL_HTTP_WITH_PARAMETERS("name,asc", 2, "bla bla", "bla bla")
Run Code Online (Sandbox Code Playgroud)
Observable 1 发出“name,desc”值
$1 = name,desc
$2 = 2 ==> has to be 1 again
$3 = bla bla
$4 = bla bla
CALL_HTTP_WITH_PARAMETERS("name,desc", 1, "bla bla", "bla bla")
Run Code Online (Sandbox Code Playgroud)
其他
Observable 3 发出“新值”值
$1 …Run Code Online (Sandbox Code Playgroud) 我需要的是当每个listviewitem的鼠标在工具提示中向我显示每个数据.
这是我的观点的一部分
...
...
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf;
...
...
private ObservableCollection<Articulo> _articulos;
private Articulo _articuloSeleccionado;
public ObservableCollection<Articulo> Articulos
{
get { return _articulos; }
set
{
_articulos = value;
RaisePropertyChanged();
}
}
public Articulo ArticuloSeleccionado
{
get { return _articuloSeleccionado; }
set
{
_articuloSeleccionado = value;
RaisePropertyChanged();
}
}
Run Code Online (Sandbox Code Playgroud)
我的.xalm
<ListView Name="lvResultado"
ItemsSource="{Binding Articulos}"
SelectedItem="{Binding ArticuloSeleccionado}">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.View>
<GridView>
<GridViewColumn Header="Código de barras" Width="200" DisplayMemberBinding="{Binding CodigoDeBarras}"/>
<GridViewColumn Header="Descripción" Width="250" DisplayMemberBinding="{Binding Descripcion}"/>
</GridView> …Run Code Online (Sandbox Code Playgroud) 我正在尝试UserManager从原始内容创建自己的扩展,并且当我通过电子邮件进行搜索时,找不到用户。但是,如果我从上下文进行搜索,那么我是否找到了用户(请参见Get方法)。为了验证它是否确实实现良好,我重写了该FindByEmailAsync方法并确实对其进行了调用,但是我不知道为什么用户找不到它。一些帮助?谢谢!
public void ConfigureServices(IServiceCollection servicesCollection)
{
servicesCollection.AddDbContext<MyIndentityContext>(currentOptions =>
currentOptions.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
servicesCollection.AddIdentity<ApplicationUser, ApplicationRole>()
.AddEntityFrameworkStores<MyIndentityContext>()
.AddRoleStore<ApplicationRoleStore>()
.AddUserStore<ApplicationUserStore>()
.AddUserManager<ApplicationUserManager>()
.AddRoleManager<ApplicationRoleManager>()
.AddSignInManager<ApplicationSignInManager>()
.AddDefaultTokenProviders();
...
...
...
}
public class MyIndentityContext : IdentityDbContext<ApplicationUser, ApplicationRole, string>
{
private readonly IConfiguration _configuration;
private readonly IHttpContextAccessor _httpContextAccessor;
public MyIndentityContext(DbContextOptions dbContextOptions, IHttpContextAccessor httpContextAccessor,
IConfiguration configuration)
: base(dbContextOptions)
{
_configuration = configuration;
_httpContextAccessor = httpContextAccessor;
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.HasDefaultSchema("Sample.API");
}
}
public class ApplicationRoleManager : RoleManager<ApplicationRole>
{
public ApplicationRoleManager(IRoleStore<ApplicationRole> roleStore, …Run Code Online (Sandbox Code Playgroud) 我需要从"ModelState"中捕获错误以发送个性化消息.问题是如果UserDTO的属性具有属性"Required",则永远不会执行过滤器.如果删除它,请输入过滤器,但modelState有效
[HttpPost]
[ModelState]
public IActionResult Post([FromBody] UserDTO currentUser)
{
/*if (!ModelState.IsValid)
{
return BadRequest();
}*/
return Ok();
}
public class ModelStateAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext currentContext)
{
if (!currentContext.ModelState.IsValid)
{
currentContext.Result = new ContentResult
{
Content = "Modelstate not valid",
StatusCode = 400
};
}
else
{
base.OnActionExecuting(currentContext);
}
}
}
public class UserDTO
{
[Required]
public string ID { get; set; }
public string Name { get; set; }
}
Run Code Online (Sandbox Code Playgroud) 我需要创建自己的类来处理EF Core 2.1中的身份。我有以下内容,但是当要使用控制器的方法时,出现以下错误
尝试激活“ Sample.API.Models .Identity.Managers.ApplicationUserManager”时,无法解决“ Sample.API.Models.Identity.Stores.ApplicationUserStore”类型的服务。
public void ConfigureServices(IServiceCollection servicesCollection)
{
servicesCollection.AddDbContext<MyIndentityContext>(currentOptions =>
currentOptions.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
servicesCollection.AddIdentity<ApplicationUser, ApplicationRole>()
.AddEntityFrameworkStores<MyIndentityContext>()
.AddRoleStore<ApplicationRoleStore>()
.AddUserStore<ApplicationUserStore>()
.AddUserManager<ApplicationUserManager>()
.AddRoleManager<ApplicationRoleManager>()
.AddSignInManager<ApplicationSignInManager>()
.AddDefaultTokenProviders();
servicesCollection.AddTransient<UserManager<ApplicationUser>, ApplicationUserManager>();
servicesCollection.AddTransient<SignInManager<ApplicationUser>, ApplicationSignInManager>();
servicesCollection.AddTransient<RoleManager<ApplicationRole>, ApplicationRoleManager>();
servicesCollection.AddTransient<IUserStore<ApplicationUser>, ApplicationUserStore>();
servicesCollection.AddTransient<IRoleStore<ApplicationRole>, ApplicationRoleStore>();
...
...
...
}
public class MyIndentityContext : IdentityDbContext<ApplicationUser, ApplicationRole, string>
{
private readonly IConfiguration _configuration;
private readonly IHttpContextAccessor _httpContextAccessor;
public MyIndentityContext(DbContextOptions dbContextOptions, IHttpContextAccessor httpContextAccessor,
IConfiguration configuration)
: base(dbContextOptions)
{
_configuration = configuration;
_httpContextAccessor = httpContextAccessor;
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.HasDefaultSchema("Sample.API");
} …Run Code Online (Sandbox Code Playgroud) 我需要将一个字符串数组从 ajax 发送到控制器,我需要返回一个要下载的文件。我已经看过了,到处都说同样的解决方案,但我不能让它工作。我已经在控制器上休息了,但从未进入。 控制器在不同的项目中。
SOLUTION
PROJECT 1
Controllers
ApiControllers
RenderMvcControllers
SurfaceControllers
ExportController
PROJECT 2
function GetData() {
var stringArray = new Array();
stringArray[0] = "item1";
stringArray[1] = "item2";
stringArray[2] = "item3";
var postData = { values: stringArray };
$.ajax({
type: "POST",
url: "/umbraco/Surface/Export/HandleDownloadFile",
data: postData,
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
alert();
alert(data.Result);
},
error: function (data) {
alert("Error: " + data.responseText);
},
});
}
class ExportController : SurfaceController
{
[HttpPost]
public ActionResult HandleDownloadFile(string[] productList)
{
return …Run Code Online (Sandbox Code Playgroud) c# ×5
angular ×4
angular6 ×3
asp.net-core ×3
rxjs ×2
asp.net-mvc ×1
javascript ×1
listviewitem ×1
typescript ×1
umbraco ×1
wpf ×1
xaml ×1