Javascript 角度2中局部迭代作用域变量的设置值
我有下面的HTML的角度Javascript 角度2中局部迭代作用域变量的设置值,javascript,jquery,angular,Javascript,Jquery,Angular,我有下面的HTML的角度 <span *ngIf="ControllerType?.AttributeID =='Controller Type'"> <select multiple name="ControllerType.Default" [(ngModel)]="ControllerType1"> <option *ngFor="let z of
<span *ngIf="ControllerType?.AttributeID =='Controller Type'">
<select multiple name="ControllerType.Default" [(ngModel)]="ControllerType1">
<option *ngFor="let z of ControllerType.Options" value={{z.OptionID}}>
{{z.OptionID}}
</option>
</select>
</span>
{{z.OptionID}
我想知道的是如何设置ControllerType.Default
,它是字符串类型,以获取在ControllerType1
中选择的值。因此,选择并存储在ControllerType1
中的任何值也应存储在ControllerType.Default
<span [ngInit]="ControllerType1 = ControllerType.Default" *ngIf="ControllerType?.AttributeID =='Controller Type'">
<select multiple name="ControllerType.Default" [(ngModel)]="ControllerType1" (ngModelChange)="ControllerType.Default = ControllerType1">
<option *ngFor="let z of ControllerType.Options" value={{z.OptionID}}>
{{z.OptionID}}
</option>
</select>
</span>
在Select标记之后和迭代内部执行此操作会出错。使用
ngModelChange中的表达式
<span *ngIf="ControllerType?.AttributeID =='Controller Type'">
<select multiple name="ControllerType.Default" [(ngModel)]="ControllerType1" (ngModelChange)="ControllerType.Default = ControllerType1">
<option *ngFor="let z of ControllerType.Options" value={{z.OptionID}}>
{{z.OptionID}}
</option>
</select>
</span>
在ngInit指令下指定表达式
[ngInit]=“ControllerType1=ControllerType.Default”
{{z.OptionID}
非常酷..如何在页面刷新时重新加载值,以便基本上执行相反的操作{{{ControllerType1=ControllerType.Default}}因此,将显示已保存的选定值。如果要在页面刷新后保留这些值,则需要将if存储在localstorage或其他内容中,并在页面加载时检索。是的,我正在将其存储在DB中。ControllerType.Default是存储方式,是页面刷新时包含存储值的内容。但是如何存储我是否将其映射到ControllerType1以便它显示在页面上。在导出类中,分配ControllerType1=ControllerType。默认初始值有很多这样的选择类型,然后我还必须在导出类中执行循环..我是否可以在已经迭代的html中执行类似的操作。
<span [ngInit]="ControllerType1 = ControllerType.Default" *ngIf="ControllerType?.AttributeID =='Controller Type'">
<select multiple name="ControllerType.Default" [(ngModel)]="ControllerType1" (ngModelChange)="ControllerType.Default = ControllerType1">
<option *ngFor="let z of ControllerType.Options" value={{z.OptionID}}>
{{z.OptionID}}
</option>
</select>
</span>