我在Angular 2的下拉列表中预先选择值时遇到了问题.
我在组件中设置了一组颜色,我成功绑定到下拉列表.我遇到的问题是在页面init上预先选择一个值.
该行[selected]="car.color.id == x.id"应选择已在汽车模型上设置的值,this.car.color = new Colour(-1,'');但这仅在我将汽车颜色ID设置为列表中的最后一项(在本例中为黑色)时才有效this.car.color = new Colour(4,'');
我使用的是最新版本的Angular(rc3),并且在rc1和rc2中遇到过相同的问题.
这是一个显示问题的掠夺者.
https://plnkr.co/edit/yIVEeLK7PUY4VQFrR48g?p=preview
另一个奇怪的方面是,在查看元数据时,Angular已将所选值设置为true.
但下拉仍然显得空洞.
这些相关问题似乎是一个单独的问题.
如何在Angular2中的对象数组上使用select/option/NgFor
问候
史蒂夫
组件模板
<div>
<label>Colour</label>
<div>
<select [(ngModel)]="car.colour"">
<option *ngFor="let x of colours" [value]="x.id" [selected]="car.color.id == x.id">{{x.name}}</option>
</select>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
零件
import { Component, OnInit } from '@angular/core';
import {AbstractControl,FORM_DIRECTIVES } from '@angular/common';
@Component({
selector:'dropdown',
templateUrl:'app/components/dropdown/dropdown.component.html',
directives:[FORM_DIRECTIVES]
})
export class DropdownComponent implements OnInit
{
car:Car = new Car();
colours = Array<Colour>();
ngOnInit(): …Run Code Online (Sandbox Code Playgroud) 我们的项目正在迁移到Angular4,并@angular/common/http Httpclient用作默认的网络工具.但我发现body删除功能中没有参数.如何添加正文以删除功能?谢谢.
我使用angular中的复选框来选择多个数据并且我试图在表单上获取复选框的值.相反,获取值im得到的值为true.我试过以下代码帮我提前谢谢
export class CreatesessionComponent implements OnInit {
form : FormGroup ;
constructor(private formBuilder: FormBuilder) {
}
ngOnInit() {
this.form = this.formBuilder.group({
useremail : new FormArray([
new FormControl('',Validators.required)
])
});
}
}
Run Code Online (Sandbox Code Playgroud)
userdata是动态数组,我将从数据库中获取
<div class = "row" formArrayName="useremail; let k = index">
<div class="col-md-8 col-sm-5 col-xs-12 col-lg-8">
<div *ngFor="let data of userdata">
<div class="col-md-6">
<input type="checkbox" name="useremail" formControlName ="{{k}}" [value]="data.email">{{data.email}}
</div>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud) 我打算用C#重写我的Python Tile Engine.它使用所有游戏对象的列表并在屏幕上呈现它们.我的问题是,与Python不同,你可以在数组中添加几乎任何东西(例如x = ["jj",1,2.3,'G',foo])你只能在C#数组中添加一种类型的对象(int [] x = {1,2,3};).是否有任何动态数组(类似于ArrayList()类)或允许您将不同类型打包到单个数组中的东西?因为所有游戏对象都是单独的类.
我需要在从http post请求中获取数据后调用方法
service:request.service.TS
get_categories(number){
this.http.post( url, body, {headers: headers, withCredentials:true})
.subscribe(
response => {
this.total = response.json();
}, error => {
}
);
}
Run Code Online (Sandbox Code Playgroud)
组件:categories.TS
search_categories() {
this.get_categories(1);
//I need to call a Method here after get the data from response.json() !! e.g.: send_catagories();
}
Run Code Online (Sandbox Code Playgroud)
只有在我改为:
service:request.service.TS
get_categories(number){
this.http.post( url, body, {headers: headers, withCredentials:true})
.subscribe(
response => {
this.total = response.json();
this.send_catagories(); //here works fine
}, error => {
}
);
}
Run Code Online (Sandbox Code Playgroud)
但我需要调用的方法send_catagories()调用后构件的内部this.get_categories(1);这样的
组件:categories.TS
search_categories() { …Run Code Online (Sandbox Code Playgroud) 我有一个表作为HTML文档的整个内容(为了合法的表目的......它是表数据,而不是布局).某些单元格指定了宽度和高度(不是通过css,而是在表结构中使用旧的大小调整内联),但整个表格没有指定宽度或高度.这是一个相当大的桌子,但如果有适当的缩放比例(约70%),它可以打印出来,以便很好地贴合在一张纸上.这可以通过使用IE,Firefox和Chrome的打印机设置中的"缩放页面"功能来完成.有没有办法扩展整个页面(在我的情况下只是这个表)作为打印样式表的一部分(我知道@media print {}但是那里的语句被忽略了......问题在于正确的命令用于缩放,而不是设置print css)?我可以用这个缩放屏幕视图:
body {
transform: scale(.7);
}
Run Code Online (Sandbox Code Playgroud)
但是在打印时,Chrome(和其他人)会忽略我的比例并自动缩放表格以适应纸张的宽度,这会导致我的表格被分割到第二页.我也试过应用这个但没有成功:
table {page-break-inside: avoid;}
Run Code Online (Sandbox Code Playgroud) 我在WebAPI项目中安装了以下软件包及其依赖项:
Ninject.Web.WebApi
Ninject.Web.WebApi.OwinHost
我这纯粹是作为web-api项目运行的.没有MVC.
当我运行我的应用程序并发POST送到AccountController的Register操作时,我得到以下错误:
{
"message":"An error has occurred.",
"exceptionMessage":"An error occurred when trying to create a controller of type 'AccountController'. Make sure that the controller has a parameterless public constructor.",
"exceptionType":"System.InvalidOperationException",
"stackTrace":" at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)\r\n at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__0.MoveNext()",
"innerException":{
"message":"An error has occurred.",
"exceptionMessage":"Type 'RPT.Api.Controllers.AccountController' does not have a default constructor",
"exceptionType":"System.ArgumentException",
"stackTrace":" at System.Linq.Expressions.Expression.New(Type type)\r\n at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.GetInstanceOrActivator(HttpRequestMessage request, Type controllerType, Func`1& activator)\r\n at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage …Run Code Online (Sandbox Code Playgroud) c# dependency-injection ninject asp.net-web-api asp.net-web-api2
我有一个对象列表(汽车).对于列表中的每辆车,我需要遍历它并找到DateTime类型的任何属性.如果我找到DateTime的属性,我需要获取值并进行时间转换.现在,我们只需将DateTime属性值打印到控制台即可.我有一些问题需要理解我需要放在prop.GetValue函数的第一个参数中.任何帮助,将不胜感激!
foreach (var car in carList)
{
foreach (PropertyInfo car in car.GetType().GetProperties())
{
var type = Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType;
if (type == typeof (DateTime))
{
Console.WriteLine(prop.GetValue(???, null).ToString());
}
}
}
Run Code Online (Sandbox Code Playgroud) 我知道它之前已经被问过并回答了 - 我问的原因是因为(我认为)我尝试了所有建议的解决方案来解决这个问题,但仍然无法解决它.
我有一个ASP.NET Web API 2.0项目.我有Autofac,Autofac.Mvc5并Autofac.WebApi2安装了依赖项.当我尝试调用API控制器时,我收到以下错误:
尝试创建"MyController"类型的控制器时发生错误.确保控制器具有无参数的公共构造函数.
在我Global.asax的电话中IocConfig.Config(),我已将其置于其中App_Start:
public static class IocConfig
{
public static void Config()
{
var builder = new ContainerBuilder();
builder.RegisterType<MyLogger>().As<IMyLogger>();
builder.RegisterApiControllers(Assembly.GetCallingAssembly());
builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration);
WebApiApplication.Container = builder.Build();
DependencyResolver.SetResolver(
new AutofacDependencyResolver(WebApiApplication.Container));
GlobalConfiguration.Configuration.DependencyResolver =
new AutofacWebApiDependencyResolver(WebApiApplication.Container);
}
}
Run Code Online (Sandbox Code Playgroud)
这是以下构造函数MyController:
public MyController(IMyLogger logger)
Run Code Online (Sandbox Code Playgroud)
当我尝试调用它时,我得到有关构造函数的指定错误.我错过了什么?
您好我是新来的角料,我想创建形式的卡格r列c列的(r X c)动态.例如,如果我有5个用户,那么它应该创建r=3并c=2如下.
user1 user2
user3 user4
user5
Run Code Online (Sandbox Code Playgroud)
我实现了如下:
<md-grid-list cols="2" rowHeight="200px" gutterSize="10px">
<md-grid-tile class="divcls" *ngFor="let user1 of users">
<md-card fxLayoutWrap="wrap" fxLayout="column" fxFlex="90%" fxLayoutGap="16px">
<md-card-title>User : {{user1.name}}</md-card-title>
<md-card-content>{{user1.details}}</md-card-content>
<md-card-actions>
<button md-button>LIKE</button>
<button md-button>SHARE</button>
</md-card-actions>
</md-card>
</md-grid-tile>
</md-grid-list>
Run Code Online (Sandbox Code Playgroud)
这是正确的方法吗?因为当我尝试调整窗口大小时,它将与卡和网格单元重叠.我在网上查了一下,但没有找到任何干净的方法与纯角材料方式.请指导我以更好的方法实现相同的目标.
angular ×5
c# ×4
.net ×2
typescript ×2
arrays ×1
asp.net ×1
autofac ×1
css ×1
html-table ×1
javascript ×1
ninject ×1
promise ×1
reflection ×1
subscribe ×1