angularjs-ng-change

AngularJS - select tag - getting attribute from option when selected

你。 提交于 2019-12-02 10:23:06
问题 So I have a select tag that shows some options and I wish that when an option is selected it takes the data-something attribute and pastes its value (of the attribute) in the input element I have. It is only demonstrative, value attribute should be send in the form. <input ng-model="refreshedByExample" type="text"> <select ng-model="example"> <option value="1" data-something="valueForRefreshedByExample1">1</option> <option value="2" data-something="valueForRefreshedByExample2">2</option>

AngularJS - select tag - getting attribute from option when selected

天大地大妈咪最大 提交于 2019-12-02 03:57:27
So I have a select tag that shows some options and I wish that when an option is selected it takes the data-something attribute and pastes its value (of the attribute) in the input element I have. It is only demonstrative, value attribute should be send in the form. <input ng-model="refreshedByExample" type="text"> <select ng-model="example"> <option value="1" data-something="valueForRefreshedByExample1">1</option> <option value="2" data-something="valueForRefreshedByExample2">2</option> <option value="3" data-something="valueForRefreshedByExample3">3</option> </select> Any ideas? Thanks a lot

Input cursor position jumps to end with ng-change()

北城以北 提交于 2019-12-01 23:41:22
I have an instance where I'm replacing the value of ngModel through ngChange . The cursor jumps to the end of the input field after each change (assuming because I'm assigning the result to the same $scope variable.) I'd like to know how I can prevent this behavior? $scope.compute1 = 0; $scope.compute2 = 10; $scope.math = function() { $scope.compute1 = parseInt($scope.compute1); $scope.compute2 = parseInt($scope.compute2); $scope.compute1 = parseInt($scope.compute1); }; fiddle Example of problem: if a user types in 1000. It's fine. But then if they want to go back and change the number to

ngChange fires before value makes it out of isolate scope

前提是你 提交于 2019-11-30 20:17:17
//main controller angular.module('myApp') .controller('mainCtrl', function ($scope){ $scope.loadResults = function (){ console.log($scope.searchFilter); }; }); // directive angular.module('myApp') .directive('customSearch', function () { return { scope: { searchModel: '=ngModel', searchChange: '&ngChange', }, require: 'ngModel', template: '<input type="text" ng-model="searchModel" ng-change="searchChange()"/>', restrict: 'E' }; }); // html <custom-search ng-model="searchFilter" ng-change="loadResults()"></custom-search> Here is a simplified directive to illustrate. When I type into the input,

When to use $watch or ng-change in Angularjs

馋奶兔 提交于 2019-11-28 19:06:40
When should I use angular $watch functions and when use ng-change angularjs directive? To me, they both can do the same. Are there any differences or usage patterns between them? They are not the same, clearly. One is used solely in the controller; the other is a directive on an input element. But even in their application they differ. When you use $watch the watched expression will be evaluated on every digest cycle, and if there is a change, the handler is invoked. With ng-change , the handler is invoked explicitly in response to an event. With $watch , change can come from anywhere: user

How can I make angularjs ngChange handler be called only when user finishes typing

一个人想着一个人 提交于 2019-11-28 16:11:21
I have an input field, where I want to apply the variant of ngChange . The input field is sort of binding with an ajax call, when user changes the input, the server side will process the data, however, I don't wanna make the call too often. Say the user wanna input a really string, I want the call be made only after user finishes the word he is about to type. Nevertheless, I don't wanna use event such as blur. What would be a better way to implement this, rather than setTimeout ? Use ng-model-options in Angular > 1.3 <input type="text" ng-model="vm.searchTerm" ng-change="vm.search(vm

How to add ng-model functionality to a component

五迷三道 提交于 2019-11-28 13:10:48
Angular ng-change on ng-model passed into child directive Basically, I want to be able to pass in ng-model from a parent directive to a child directive. I could just in a 2-way binded value, but then I wouldn't be able to use a ng-change in the parent directive on the child element. I could also use ng-click, but this wouldn't work with a non-clicking change (such as a text area instead of a checkbox). So I'm wondering if there's a way to allow a custom directives to have a ng-model/ng-change pair similar to how inputs, buttons, text areas and other html elements can. I want to avoid using

How can I denote which input fields have changed in AngularJS

这一生的挚爱 提交于 2019-11-27 19:17:56
I'm working on an edit form (user.html) that PUTs data to an API, but I'd like to avoid PUTting all the data in the form. I'd like to PUT just the changed items. I've seen the use of dirty and pristine when working with forms, but this applies to any change in the form. I've also seen the use of ng-change, but I don't want to trigger an action on a change to one element, just denote that the changed element should be included in the PUT. Anyone found a way to denote only the input fields that have changed? If you put the input in a form with a name attribute and then give the input a name

Angular - ng-change not firing when ng-model is changed

浪尽此生 提交于 2019-11-27 15:49:12
问题 The input is the following: <input type="text" ng-model="repair.test" ng-change="action()" /> The action() is executed when I manually type and change the input. However if I change the repair.test value by some other function programmatically, it doesnt fire the ng-change's action. I have read the angular tutorial and it's probably the expected behavior. https://docs.angularjs.org/api/ng/directive/ngChange "The expression is not evaluated when the value change is coming from the model." <- I

How to implement an ng-change for a custom directive

陌路散爱 提交于 2019-11-27 12:17:11
I have a directive with a template like <div> <div ng-repeat="item in items" ng-click="updateModel(item)"> <div> My directive is declared as: return { templateUrl: '...', restrict: 'E', require: '^ngModel', scope: { items: '=', ngModel: '=', ngChange: '&' }, link: function postLink(scope, element, attrs) { scope.updateModel = function(item) { scope.ngModel = item; scope.ngChange(); } } } I would like to have ng-change called when an item is clicked and the value of foo has been changed already. That is, if my directive is implemented as: <my-directive items=items ng-model="foo" ng-change="bar