angular2-ngmodel

Angular 2: Select dropdown not selecting option despite “selected” attribute

巧了我就是萌 提交于 2019-12-12 12:32:46
问题 I have the following code for a select dropdown: <select id="UnitOfMeasurementId" name="UnitOfMeasurementId" [(ngModel)]="UnitOfMeasurementId"> <option *ngFor="let unit of UnitOfMeasurements" [ngValue]="unit.Value" [selected]="unit.Selected">{{unit.Text}}</option> </select> Each item in the UnitOfMeasurements array looks something like this: Selected: false Text: "lb" Value: "1" Or this: Selected: true Text: "kg" Value: "3" [(ngModel)]="UnitOfMeasurementId" contains the value of the item that

Binding the value in a textarea

爱⌒轻易说出口 提交于 2019-12-12 08:21:07
问题 I'm trying to do the simplest two way binding in Angular2. I would like to share a variable between my component and it's template. My template is: <textarea [(ngModel)]="currentQuery"></textarea> And my component is: import { Component } from '@angular/core'; import { ViewChild } from '@angular/core'; import { OnInit } from '@angular/core'; @Component({ moduleId: module.id, selector: 'vs-home', templateUrl: 'home.component.html' }) export class HomeComponent { private currentQuery: string =

How to get selected option from select and assign it to select ngModel

梦想与她 提交于 2019-12-11 04:38:35
问题 I have the following select menu: <div class="medium-3 columns"> <label>First Menu <select name="first-menu"> <option *ngFor="let i of items" [value]="i.name">{{i.name}}</option> </select> </label> </div> I would assing a model to the select menu so i edited the code in the following way (i see it here): <div class="medium-3 columns"> <label>First menu <select [ngModel]="myForm.firstMenu" (ngModelChange)="onSelected($event)" name="first-menu"> <option *ngFor="let i of items" [value]="i.name">

ErrorHandler in Angular2

落爺英雄遲暮 提交于 2019-12-09 16:43:26
问题 I have a question about new class ErrorHandler (was included to RC.6). I did example from official docs: https://angular.io/docs/ts/latest/api/core/index/ErrorHandler-class.html import{ErrorHandler} from "@angular/core"; import{NgModule} from "@angular/core"; export class MyErrorHandler implements ErrorHandler { call(error: any, stackTrace: any = null, reason: any = null) { // do something with the exception console.log("do something with the exception"); } // I handle the given error. public

Angular 2 + how to select and loop over multiple elements with the same selector (elementRef.nativeElement)

∥☆過路亽.° 提交于 2019-12-08 01:31:52
问题 In my component I am trying to unselect all checkboxes with the same class name. querySelector selects only the first one each time (or once)... and querySelectorAll does not select anything. this is the function. I know its wrong to use jQuery like that but it illustrates my goal. unsetAllOptions(){ var self = this; var i = 0; $("input.option_input").each(function(){ i++; var element = self.elRef.nativeElement.querySelector("input.option_input")[i]; if(element.checked){ // console.log(i)

Angular 2 + how to select and loop over multiple elements with the same selector (elementRef.nativeElement)

别说谁变了你拦得住时间么 提交于 2019-12-06 04:08:02
In my component I am trying to unselect all checkboxes with the same class name. querySelector selects only the first one each time (or once)... and querySelectorAll does not select anything. this is the function. I know its wrong to use jQuery like that but it illustrates my goal. unsetAllOptions(){ var self = this; var i = 0; $("input.option_input").each(function(){ i++; var element = self.elRef.nativeElement.querySelector("input.option_input")[i]; if(element.checked){ // console.log(i) console.log('unchecking:',i); element.checked=false; element.dispatchEvent(new Event('change')); element =

How to change the date format in the datepicker of Angular ngx-bootstrap inside a form

▼魔方 西西 提交于 2019-12-03 17:47:39
问题 Using ngx-bootstrap Datepicker in an Angular 4 application, I know that normally you can specify the date format this way: <input id="from" name="from" bsDatepicker [(bsValue)]="myModel" value="{{ myModel | date:'yyyy-MM-dd'}}"> but this time I'm inside a template-driven Angular form, so my input is not bound to a variable like myModel in the example above, but it's just bound to the form: <input id="from" name="from" bsDatepicker ngModel> so how can I specify the date format in this case?

How to change the date format in the datepicker of Angular ngx-bootstrap inside a form

那年仲夏 提交于 2019-12-03 13:22:52
Using ngx-bootstrap Datepicker in an Angular 4 application, I know that normally you can specify the date format this way: <input id="from" name="from" bsDatepicker [(bsValue)]="myModel" value="{{ myModel | date:'yyyy-MM-dd'}}"> but this time I'm inside a template-driven Angular form, so my input is not bound to a variable like myModel in the example above, but it's just bound to the form: <input id="from" name="from" bsDatepicker ngModel> so how can I specify the date format in this case? Edit : it looks like that a way to achieve this is by creating a new variable newVar inside the component

angular2 access ngModel variable from a directive

ぃ、小莉子 提交于 2019-12-03 09:25:08
问题 I am trying to build a datetime picker directive like the following. <input [(ngModel)]="date1" datetime-picker date-only /> and date1 is assigned as a Date, e.g., new Date() When I display this in html, text in input element looks like the following Thu Jan 01 2015 00:00:00 GMT-0500 I want to display like the following instead 2015-01-01 00:00:00 I want to format date WITHIN a directive using DatePipe instead of showing result from default toString() function. My question is; "within a

Set default select list value Angular2

我的梦境 提交于 2019-12-02 06:17:33
I want to set the default option for the select in angular 2 as "Select an option". Here is the code that I have so far: HTML <div class="form-group"> <label class="col-md-4 control-label" for="CustomFix">Select an option:</label> <div class="col-md-4"> <select id="example" name="example" class="form-control" [(ngModel)]="exampleArray" (ngModelChange)="changes()"> <option disabled selected>Select a Custom Fix</option> <option *ngFor="let example of exampleArray" [ngValue]="example">{{example.attribute }}</option> </select> </div> </div> Typescript changes(){ console.log(this.example.option); }