angular-ngmodel

Angular2 - Update model on button click

。_饼干妹妹 提交于 2019-12-01 12:09:57
When using the angular2 ngModel for two-way data binding: <input [(ngModel)]="heroName"> Is there a way to only update the model once a button is clicked? Or be able to cancel the changes that the user made to the input control? I am aware of the other approach where we can split the [(ngModel)] in its [] and () and only update the input on blur or when the Enter key is pressed etc - but this is not what I want. I need this behavious because, the user must be able to cancel the changes. Thanks You can do following for that, DEMO : http://plnkr.co/edit/OW61kGGcxV5MuRlY8VO4?p=preview {{heroName}

Angular2 - Update model on button click

蓝咒 提交于 2019-12-01 10:05:43
问题 When using the angular2 ngModel for two-way data binding: <input [(ngModel)]="heroName"> Is there a way to only update the model once a button is clicked? Or be able to cancel the changes that the user made to the input control? I am aware of the other approach where we can split the [(ngModel)] in its [] and () and only update the input on blur or when the Enter key is pressed etc - but this is not what I want. I need this behavious because, the user must be able to cancel the changes.

AngularJS - declare ng-model directly on the <form> element

假装没事ソ 提交于 2019-12-01 09:07:43
In AngularJS, is there any way to declare ng-model directly on the <form> element instead of having to do it on every single control/input of that form and then be able to access the values of the controls in the controller through their names? Specifically, if you have a form like this, <form> <input type="text" name="email"> <input type="text" name="age"> </form> typically, you'd do something like this, <form> <input type="text" ng-model="user.email"> <input type="text" ng-model="user.age"> <form> which then gives you access to the user object and its properties in the controller: $scope

Angular 2 ng module imports

断了今生、忘了曾经 提交于 2019-12-01 09:00:26
问题 What is the significance of imports metadata of ngmodule decorator, when we are importing files at top. Difference between both the inputs. 回答1: These imports are entirely different concepts. The imports at the top of the file are TypeScript imports to make classes, interfaces and variables known to the current file and are not related to Angular2. The @NgModule() imports are to make exports: [] of the imported @NgModule() s known to the importing @NgModule() so that they applied to

AngularJS - declare ng-model directly on the <form> element

。_饼干妹妹 提交于 2019-12-01 05:31:01
问题 In AngularJS, is there any way to declare ng-model directly on the <form> element instead of having to do it on every single control/input of that form and then be able to access the values of the controls in the controller through their names? Specifically, if you have a form like this, <form> <input type="text" name="email"> <input type="text" name="age"> </form> typically, you'd do something like this, <form> <input type="text" ng-model="user.email"> <input type="text" ng-model="user.age">

How to set default selected values in multiselect with ngModel in Angular 2

╄→гoц情女王★ 提交于 2019-11-30 16:12:37
问题 How to set default selected values in multiselect. I get current_options and all_options from database and I want to update current_options and send new values do database again. Updating database works but when I refresh page none of options are selected. current_options = [{id:1, name:'name1'}]; #from database all_options = [{id:1, name:'name1'},{id:2, name:'name2'}]; #from database My template: <select multiple name="type" [(ngModel)]="current_options"> <option *ngFor="let option of all

Angular 4 checkbox trigger change event on model change

喜你入骨 提交于 2019-11-30 13:43:40
HTML <input type="checkbox" id="1" [(ngModel)]="filter" (change)="onFilterChange($event)"> CheckBox <button (click)="filter = !filter">Change Status</button> TS export class HelloWorld { filter : false; onFilterChange() { console.log('filter change called'); } } When I directly click on the check box change event is triggered. But when I click on "Change Status" button checkbox status is changing but change event is not triggering. Can some one please let me know how to do this? Sajeetharan We have to achieve this functionality with event handler and not with 2 way binding <input type=

AngularJS set global ngModelOptions

懵懂的女人 提交于 2019-11-30 11:22:44
问题 The default behaviour for updating ngModel (and subsequently validation) is on change ; I would like to change that to on blur . The docs only explain how to do this on a case-by-case basis via: <ANY ng-model-options="{ updateOn: 'blur' }"></ANY> . I went so far as to look thru the source code, but somehow neither ngModelOptions nor ng-model-options is found (despite both occurring in the documentation, which is scraped from the source code). 回答1: While the ngModel decorators written by Jon

Setting ngTrueValue and ngFalseValue to numbers

非 Y 不嫁゛ 提交于 2019-11-30 03:13:11
Update : question is obsolete for latest Angular version, see tsh's comment on this post I have bound a checkbox to a value: <input type="checkbox" ng-model="checkbox" ng-true-value="1" ng-false-value="0" /> The value of the checkbox is set to 1 in the controller: function Controller($scope) { $scope.checkbox = 1 } However, initially the checkbox does not appear checked. If I change the initial value of $scope.checkbox to "1" , it does. ( jsfiddle demo ) I have tried all kinds of variations: ng-true-value="{{1}}" ng-true-value="{{Number(1)}}" ng-true-value="{{parseInt('1')}}" None of them work

Get user input from textarea

自闭症网瘾萝莉.ら 提交于 2019-11-30 01:44:33
I'm new to angular2. I want to store user input from a text area in a variable in my component so I can apply some logic to this input. I tried ngModel but it doesn't work. My code for the textarea: <textarea cols="30" rows="4" [(ngModel)] = "str"></textarea> And inside my component: str: string; //some logic on str But I don't get any value in str inside my component. Is there an error with the way I'm using ngModule ? Arthur Qocharyan <pre> <input type="text" #titleInput> <button type="submit" (click) = 'addTodo(titleInput.value)'>Add</button> </pre> { addTodo(title:string) { console.log