angular-ngmodel

One-Way or One-Time binding in Angular and Watchers

落花浮王杯 提交于 2019-12-25 07:36:39
问题 I have a question about how to avoid watchers when you have readonly input textbox in AngularJS. I have created plunker for it : plunker link : OneWay Binding using ng-value This shows that even when I am using ng-value for readonly input text, still a watcher has been added for it. I simple want to avoid watchers when there are readonly controls, I am asking this because in my enterprise application, even for readonly page I have more-than 200 readonly controls and watcher count there is

ng-model won't update the changed form content

时光怂恿深爱的人放手 提交于 2019-12-25 06:24:24
问题 I have a form which has a delete entry button and an add entry button. I want to output the updated form field data to formData={} , so that the submitted data will be up-to-date. However, when a fieldset is deleted, formData={} is not updated with the newest data entry information and the old form data still exist in formData={} . Here's the link for my code 回答1: try like this. var app = angular.module("app",[]); app.controller("MyCtrl" , function(){ var formCtrl = this; formCtrl.forms ={

Is it possible to bind and unbind an element on button click? - AngularJS

痞子三分冷 提交于 2019-12-25 02:48:15
问题 I created a display text and an input field and bind them together with ng-model as follow. HTML <div ng-app ng-controller="test"> <div ng-bind="content"></div> <input id="txtElem" type="text" ng-model="content"> <button ng-click="stopBinding()"> Unbind</button> <button ng-click="binding()"> Bind </button> </div> JS function test( $scope ) { $scope.content = 'Welcome'; $scope.binding = function() { angular.element(document.getElementById('txtElem')).bind(); }; $scope.stopBinding = function()

How to get checked values into an array for Angular Template Driven Form (ngModel)

天涯浪子 提交于 2019-12-24 21:15:53
问题 I'm attempting to use template driven forms, binding to a model in the html to a new instance of lets say Person . I've been unsuccessful in creating a proper binding for checkboxes to a single array property on my model. The idea is data will come from an api or other source, dynamically render checkboxes via *ngFor and bind what is selected to the Person models property which would be an array of numbers. For example: class Person { firstName: string; someCheckboxPropList: number[]; } and

Why attribute selected in <select><option> don't work with ngModel?

懵懂的女人 提交于 2019-12-24 18:43:43
问题 I have a problem with Angular 6: if I use a component based on the <select> element (combo-box), if I use it with the classic way, everything works (notice that I used the selected attribute: the result is that in the template the default option already appears as selected, as I would expect!): <select data-width="200px" title="title" name = "name" > <option value='default' selected>Default</option> <option value='1'>Value 1</option> <option value='2'>Value 2</option> </select> The problem is

Angular ngModel different view and value

北慕城南 提交于 2019-12-24 16:00:07
问题 Does ngModel controller in directive have any option to show something different from ngModel value in view, or i have to write custom html directive for input? I wrote a comma-separator directive. everything is fine, but ngModel value change from Number to String with , . I mean can i have input with value 1000000 but it shows 1,000,000 in view? Update: In the input box shows 1,000,000 , but its value be 1000000 . Update 2 I know about $formatters and $parsers . but the problem is

Generate ng-model inside ng-repeat

旧城冷巷雨未停 提交于 2019-12-24 02:09:46
问题 I have been reading a few topics but couldnt find a solution to this one I am stuck on. I am trying to add ng-model inside ng-repeat something like this: <span ng-repeat="list in lists"> <input type="checkbox" ng-model="formData.checkboxes.{{ list.value }}"> {{ list.number }} {{ list.description }} <br/> </span> and the list values are like this: $scope.lists = [ { value:'value1', number: '1', description:'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ', }, { value:'value2', number

Angular filter not working

痴心易碎 提交于 2019-12-23 23:43:39
问题 I am coding a filter that will format phone numbers in a contact form I've built however for some reason the value in the input is never being updated and I'm not sure what I'm doing wrong. Here's my HTML: <div class='form-group'> <input name='phone' ng-model='home.contact.phone' placeholder='(Area code) Phone' required ng-bind='home.contact.phone | phone' /> </div> and here's my filter: (function () { 'use strict' angular .module('Allay.phoneFilter', []) .filter('phone', function () { return

Weird behavior ionic in select, ng-model won't update

谁说我不能喝 提交于 2019-12-23 16:33:40
问题 I'm experiencing something weird, this example works in codepen but won't work in my Ionic app. When I change the option in the select tag I want to show the selected value, but it won't work, it shows undefined , i've tried in many ways. This is not the original code, the original one retrieves the values from an external API and populates the options with ngOptions (which works, it populates ok). But it won't update the value in the controller. So I decided to make it more simple, and it

two way binding not working with ng-repeat

一笑奈何 提交于 2019-12-23 08:07:23
问题 I have a simple ng-repeat list, in which i am assigning current list item value to another property on the controller as follows: <li ng-repeat="num in list"> <input type="text" ng-init="value = num" ng-model="value" /> <button type="button" class="btn btn-primary" ng-click="save()">Save</button> </li> But when i click the Save button i get default value set for $scope.value. I expect the value for the particular input text to be displayed. Here is the controller: angular.module('myApp', [])