How Do I call the function with ng-model in AngularJs?

Asked by Last Modified  

Follow 0
Answer

Please enter your answer

Senior Programmer

It's not possible to pass a function to ng-model because Angular has to be able to set the value when the user changes the input value. You cannot tell Angular to instead call a function when the value is changed. But I'd say that you're better of creating a $watch for the property as that will be...
read more
It's not possible to pass a function to ng-model because Angular has to be able to set the value when the user changes the input value. You cannot tell Angular to instead call a function when the value is changed. But I'd say that you're better of creating a $watch for the property as that will be more familiar to other Angular devs. var model1 = { value: 'hi' }; var model2 = { value: 'hello' }; $scope.model = model1; $scope.checkboxValue = true; $scope.$watch('checkboxValue', function(value) { if (value) { $scope.model = model1; } else { $scope.model = model2; } }); here you can use ng-model="checkboxValue" Thanks read less
Comments

Related Questions

How do we save Data in Angular?
First you need save the data in local storage and after this you need have a json to store data.
Raminder
What is routing in angularjs?
If you want to navigate to different pages in your application, but you also want the application to be a SPA (Single Page Application), with no page reloading, you can use the switching Route module. The...
Srikanth
0 0
9
I want to join tutorial for angularjs with asp.net mvc. Please provide the details location of class, fee, duration etc...
Hi Asif, i will provide the angular js completed course training with one project and this project are combination of angular js and mvc web api . contact me if you are interested
Asif
What is cost of final year IEEE project guidance?
It cost around Rs. 20,000/- at max.
Vivek

As web designer what is easy and useful to learn Angular or React?

If you are having prior Javascript knowledge then React is easy than Angular.
Nikunj

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons


Features of Angular JS:
Data Binding Structural Programming TDD Support Parallel Development Routing for SPA Dependency Injuction Client Side State Managment Product of Google

AngularJS Basics- 1
This is my first blog.I am just explaining the basics of AngularJS and Sample application in an interesting way so that anyone can create an Angular application. Let’s see how we can create :) Angular.js...

NgModules vs. JavaScript modules (Angular 2)
The NgModule — a class decorated with @NgModule Decorator — is a fundamental feature of Angular. JavaScript also has its own module system for managing collections of JavaScript objects. It's...

Angular Routing Overview
a. Routes: The browser is a familiar model of application navigation: Enter a URL in the address bar and the browser navigates to a corresponding page. Click links on the page and the browser...

Recommended Articles

Microsoft Excel is an electronic spreadsheet tool which is commonly used for financial and statistical data processing. It has been developed by Microsoft and forms a major component of the widely used Microsoft Office. From individual users to the top IT companies, Excel is used worldwide. Excel is one of the most important...

Read full article >

Information technology consultancy or Information technology consulting is a specialized field in which one can set their focus on providing advisory services to business firms on finding ways to use innovations in information technology to further their business and meet the objectives of the business. Not only does...

Read full article >

Whether it was the Internet Era of 90s or the Big Data Era of today, Information Technology (IT) has given birth to several lucrative career options for many. Though there will not be a “significant" increase in demand for IT professionals in 2014 as compared to 2013, a “steady” demand for IT professionals is rest assured...

Read full article >

Almost all of us, inside the pocket, bag or on the table have a mobile phone, out of which 90% of us have a smartphone. The technology is advancing rapidly. When it comes to mobile phones, people today want much more than just making phone calls and playing games on the go. People now want instant access to all their business...

Read full article >

Looking for Angular.JS Training?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you