我正在使用TypeScript处理Angular 2.我有用户管理组件,我有整个用户的表.
当单击表中的任何用户时,然后形成具有要编辑的整个属性的外观.选择用户发生事件如下:
onUserSelected(event) {
var selectedId = event.data.id;
this.selectedUser = this.users.filter(user => user.id === selectedId)[0]
}
Run Code Online (Sandbox Code Playgroud)
问题是当正在编辑selectedUser时,他的属性也会在表中发生变化而且看起来不太好.我尝试自己创建副本如下,但它没有帮助 - 用户类
clone() {
var cloned = new User(this.id, this.login, this.name, this.surname, this.phone);
return cloned;
}
Run Code Online (Sandbox Code Playgroud)
也许我正在做一些在Angular2中不好的做法?
我有将问题注入Angular 2应用程序的问题.几天前它工作正常,但现在我有错误:
原始例外:没有Http的提供商!
有主要的
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
import { LoginModule } from "./login/login.module";
import { Http } from "@angular/http";
platformBrowserDynamic().bootstrapModule(LoginModule);
Run Code Online (Sandbox Code Playgroud)
登录module.ts
@NgModule({
imports: [BrowserModule, FormsModule], // external modules for all components
declarations: [LoginComponent], // component which belong to this module
bootstrap: [LoginComponent] // component on load
})
export class LoginModule {
}
Run Code Online (Sandbox Code Playgroud)
最后在LoginModule中登录LoginComponent
import { Component } from '@angular/core';
import { AccountService } from "../data/account.service";
import { Http, Response, RequestOptions, Headers …
Run Code Online (Sandbox Code Playgroud) 我正在使用带有SignalR的Angular 2和ASP.NET Core.
我有如下错误:
XMLHttpRequest无法加载 http:// localhost:55916/signalsr // signalr/negotiate?clientProtocol = 1.5&connectionData =%5B%7B%22name%22%3A%22event%22%7D%5D&_ = 1486394845411.当请求的凭据模式为"include"时,响应中"Access-Control-Allow-Origin"标头的值不能是通配符"*".因此,不允许来源" http:// localhost:8080 "访问.XMLHttpRequest发起的请求的凭据模式由withCredentials属性控制.
有我的应用程序配置:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
var signingKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(Configuration["data:secretKey"]));
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
app.UseCors(config =>
config.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin());
app.UseWebSockets();
app.UseSignalR("/signalr");
app.UseMvc();
}
Run Code Online (Sandbox Code Playgroud)
我还有Angular 2 SignalR服务女巫
constructor(){
//setups...
this.connection = $.hubConnection(this.baseUrl + 'signalr/');
this.proxy = this.connection.createHubProxy(this.proxyName);
this.registerOnServerEvents();
this.startConnection();
}
Run Code Online (Sandbox Code Playgroud)
重新安排服务器事件:
private registerOnServerEvents(): void {
this.proxy.on('FoodAdded', (data: any) => {
debugger;
this.foodchanged.emit(data);
});
this.proxy.on('FoodDeleted', (data: any) => {
debugger;
this.foodchanged.emit('this could be …
Run Code Online (Sandbox Code Playgroud) 我在启动 ASP.NET MVC5 应用程序时遇到问题。直到现在一切都运行良好。在启动应用程序时,我收到以下错误:
无法加载文件或程序集“Microsoft.ApplicationInsights,版本=1.2.3.490,文化=中性,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。该系统找不到指定的文件。
说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其在代码中的来源的更多信息。
异常详细信息:System.IO.FileNotFoundException:无法加载文件或程序集“Microsoft.ApplicationInsights,Version=1.2.3.490,Culture=neutral,PublicKeyToken=31bf3856ad364e35”或其依赖项之一。该系统找不到指定的文件。
我安装了 Microsoft.ApplicationInsights 1.2.3。我也尝试过清理、重建、重新启动计算机、重新启动计算机并离开房间等。
有人知道如何解决这个问题吗?
我在将LINQ中的日期与实体表达式进行比较时遇到问题.我想检查一下DateTime == DateTime - whole day
.
我想这样做:
return context.Events.Any(x =>
x.UserId == id
&& x.Date >= date
&& x.Date < date.AddDays(1)
&& x.Type == EventType.StartWork);
Run Code Online (Sandbox Code Playgroud)
问题是由于AddDays()方法,LINQ上面的查询不正确.
我试过使用如下的DbFunction:
return context.Events.Any(x =>
x.UserId == id
&& x.Date >= date
&& x.Date < DbFunctions.AddDays(date, 1)
&& x.Type == EventType.StartWork);
Run Code Online (Sandbox Code Playgroud)
还有这个:
return context.Events.Any(x =>
x.UserId == id
&& DbFunctions.TruncateTime(date.Date) == date.Date
&& x.Type == EventType.StartWork);
Run Code Online (Sandbox Code Playgroud)
这些查询都没有给出预期的结果.
我有.NET Core解决方案(2.0).我有一个问题,大多数代码都有红色.然而,解决方案构建成功.
我做了什么:
以上解决方案均无效.
somone有任何修复策略吗?:)
我下载了用于合并 junit 报告的 npm 包 - https://www.npmjs.com/package/junit-merge。
问题是我有多个文件要合并,并且我正在尝试使用字符串变量来保存要合并的文件名。
当我自己编写脚本时,如下所示:
junit-merge a.xml b.xml c.xml
Run Code Online (Sandbox Code Playgroud)
这有效,正在创建合并文件,但是当我这样做时
$command = "a.xml b.xml c.xml"
junit-merge $command
Run Code Online (Sandbox Code Playgroud)
这是行不通的。错误是
错误:找不到文件
有人遇到过类似的问题吗?
我想在OCaml中获取列表的第一个和最后一个元素.我希望我的功能会像
'a list -> 'a * 'a
Run Code Online (Sandbox Code Playgroud)
我想做的是
let lista = [1;2;3;4;6;0];;
let rec first_last myList =
match myList with
[x] -> (List.hd lista,x)
| head::tail ->
first_last tail;;
first_last lista;;
Run Code Online (Sandbox Code Playgroud)
当然因为我把列表作为整数然后我正在做这样的语法
*int list -> int * 'a
Run Code Online (Sandbox Code Playgroud)
关键是我不知道如何为'a做这个功能.
方向是什么?
我在一个部分中检索具有不同对象类型的JSON.我把这部分视为动态.
我需要从这个对象获取数据,所以我创建了类似于动态数据的类,如下所示:
public class SpecificObject1
{
public string Title{get; set;}
public object[] ViewElements{get; set}
public object AnyAttributes{get; set;}
}
Run Code Online (Sandbox Code Playgroud)
以下是我想将其转换为此特定对象的方法:
var @switch = new Dictionary<Type, Action> {
{ typeof(x), () => jsonObj.Some = jsonObj.Some as SpecificObject1},
{ typeof(y), () => ......}
};
Run Code Online (Sandbox Code Playgroud)
使用as
返回null进行转换.
编辑:将属性更改为真实属性
动态包含:
AnyAttributes: {object}
Title: "title"
ViewElements: object[0]
Run Code Online (Sandbox Code Playgroud) 我有JSON数组如下:
var json = [{
id: 1,
login: "Mieszko",
name: "Misztal",
surname: "Adminek",
phone: "0413414",
role: 2
},
{
id: 2,
login: "Rafal",
name: "Robak",
surname: "Kierowczek",
phone: "5145145",
role: 1
}
];
Run Code Online (Sandbox Code Playgroud)
我还创建了User类,如下所示:
export class User extends BaseModel {
id: number;
login: string;
name: string;
surname: string;
phone: string;
roles: Roles;
admin: boolean;
driver: boolean;
isDriver(): boolean {
return this.roles === 1;
}
//other methods
}
Run Code Online (Sandbox Code Playgroud)
我的计划是将命令JSON数组转换为User数组.在JSON内部,我获得了整数角色.我班上有管理员和驱动程序布尔字段.这在复选框的ngModel中是必需的.
现在问题出在这一行之后
var users: Array<User> = JSON.parse(JSON.stringify(json));
Run Code Online (Sandbox Code Playgroud)
我无法从User类调用方法,例如users[0].isDriver()
因为编译器无法识别isDriver()方法.
有谁知道如何解决这个问题?