angular-ngmodel

AngularJS set global ngModelOptions

╄→гoц情女王★ 提交于 2019-11-30 00:43:07
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). While the ngModel decorators written by Jon/John provide a good behind the scene solution, one must also be aware that declaratively, ngModelOptions need

AngularJs - ng-model in a SELECT

試著忘記壹切 提交于 2019-11-29 21:18:42
JSfiddle Problem: I have a SELECT-element in my page, which is filled in with an ng-repeat . It also has a ng-model which has a default value. When I change the value, the ng-model adapts, that's ok. But the dropdown-list shows an empty slot at launch, where it should have the item with the default value selected instead. Code <div ng-app ng-controller="myCtrl"> <select class="form-control" ng-change="unitChanged()" ng-model="data.unit"> <option ng-repeat="item in units" ng-value="item.id">{{item.label}}</option> </select> </div> With JS: function myCtrl ($scope) { $scope.units = [ {'id': 10,

Angular 4 checkbox trigger change event on model change

耗尽温柔 提交于 2019-11-29 18:34:50
问题 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? 回答1: We have

Update AngularJS ng-model only on keypress enter?

别等时光非礼了梦想. 提交于 2019-11-29 17:03:01
问题 I have this input field I am using for a search: <input id="search_input" type="text" ng-model="filter.search_terms"> There are many other filters I use as well (checkboxes, radio, etc) and I have a $watch on filter so any changes will fire a search. The problem is that I don't want the search to fire for the text field every time I type a letter and only want it to "save" it on the filter.search_terms only once I press enter. Is there an easy way to do this or do I have to remove the ng

Dynamic ng-model name in AngularJS form

隐身守侯 提交于 2019-11-29 13:53:32
问题 I have an AngularJS form where I'm using ng-repeat to build the fields of the form dynamically based on another selection. I'm trying to generate the model name dynamically and am running into problems. <div class="form-group" ng-repeat="parameter in apiParameters"> <label for="{{parameter.paramName}}" class="col-sm-2 control-label">{{parameter.paramTitle}}</label> <div class="col-sm-3"> <input type="text" class="form-control" name="{{parameter.paramName}}" id="{{parameter.paramName}}" ng

Dynamically update ion.rangeSlider ngModel in AngularJS directive

给你一囗甜甜゛ 提交于 2019-11-29 12:11:58
I'm trying to update the value of an Ion.RangeSlider when its bound ng-model scope variable changes. The model updates when the Ion.RangeSlider is used, but not vice-versa. Other inputs with the same ng-model update when the model value changes, so this must be some special case. Edit: Woo! Here's a snippet @lin :) Also jsfiddle . var app = angular.module('ngModelIonRangeSliderDemo', []); app.controller('MainCtrl', function ($scope, $rootScope, $timeout) { $scope.someNumber = 10; }).directive('ionRangeSlider', function ionRangeSlider() { return { restrict: 'A', scope: { rangeOptions: '=',

Angular 2 ngModelChange old value

寵の児 提交于 2019-11-29 09:26:33
Can someone please tell me what is the best practice for comparing ngModel old and new value? In angular 1: $scope.$watch('someProperty', funciton(oldVal, newVal){ // code goes here }) I am asking this because (ngModelChange) never brings me the oldVal , only the newVal . In my case, I am using ngModel in a <select> tag and compare the old selection with the new one: <select [(ngModel)]="current" (ngModelChange)="onModelChange($event)"> <option *ngFor="let item of myArray" [ngValue]="item">{{item.name}} </option> </select> This might work (ngModelChange)="onModelChange(oldVal, $event); oldVal

Angular 2: How to get the selected value from different options of a form?

此生再无相见时 提交于 2019-11-29 03:56:57
I would like to use a <select> in a form to let the user being able to update values among different <option> . I have used the technique from the guide here: https://angular.io/docs/ts/latest/guide/forms.html . Here is the sample I am talking about: <div class="form-group"> <label for="type">Type :</label> <select class="form-control" [(ngModel)]="order.type" ngControl="type"> <option *ngFor="#type of types" [value]="type">{{type}}</option> </select> </div> In my order-details.component I have got an updateOrder() which calls the updateOrder() from myApp.services. My problem is when I am

Same form for creating and editing data Angular4

社会主义新天地 提交于 2019-11-29 02:18:14
Here is a form with two way-binded input fields. The goal was to create the same form to edit and create data. That was accomplished, but I am pretty sure that there could be a better way to do this (like using AbstractControl features). I also miss one fix here - if clickEdit() being clicked need to update form values with that object which user wants to edit. Thanks for any help and especially explanations about AbstractControl and NgModel .. <div> <form (ngSubmit)="clicked ? onEditSubmit($event) : onRegisterSubmit($event)" [formGroup] = "form"> <div class="form-group"> <label>Full Name<

Radio Buttons ng-checked with ng-model

吃可爱长大的小学妹 提交于 2019-11-29 01:28:28
In my HTML page, I have two sets of Boolean based radio buttons: Labeled: "Yes" and "No" / Values: True and False respectively. I'm populating a full form from a PostgreSQL database table to allow the authenticated user to view the form with populated data and edit the populated fields including the radio buttons, then save the form which will save the data to the DB. All of the other text fields populate without issue; it's both collection of radio buttons I am having an issue with pre-checkmarking the radio buttons. The below does not pre-populate the checked on front end (but adds the