Showing posts with label AngularJS. Show all posts
Showing posts with label AngularJS. Show all posts

Monday, 29 August 2016

How to use Function in AngularJS Controllers

Posted by : Manav Pandya

How to use Function in AngularJS



How to use Function in AngularJS Controllers ?


If you are new to AngularJS refer my Article : Understand Controller in AngularJS

Function in AngularJS :

  • In this article we will learn how to use Function in AngularJS

Following example shows its actual use :



<html>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>
 
<div ng-app="Manav" ng-controller="Ctrl">
 
City: <input type="text" ng-model="city"><br><br><br>
Country: <input type="text" ng-model="country"><br><br><br>
Result: {{output()}}
 
</div>
 
<script>
var app = angular.module('Manav', []);
app.controller('Ctrl', function($scope) {
    $scope.city = "Rajkot";
    $scope.country = "India";
    $scope.output=function() {
 
 return $scope.city + " " + $scope.country;
}
});
</script>
 
</body>
</html>


Here we have used Function in AngularJS , which is named 'Manav' and inside that we have taken two text box value :


  • City
  • Country

Output :

Function in AngularJS




So try it with yourself and make appropriate changes .


basic asp.net mvc tutorials, Free asp.net mvc Tutorials for beginners, mvc, asp.net mvc, .net tutorials, mvc tutorial, mvc tutorials, asp.net mvc tutorials, mvc tutorial, mvc tutorials for Beginners , asp.net mvc Basics, basic mvc, mvc4, mvc5,.net mvc

Read More

Sunday, 28 August 2016

AngularJS - Understanding Controllers

Posted by : Manav Pandya
AngularJS Understanding Controllers


AngularJS - Understanding Controllers


  • Main task of Controllers in AngularJS is to control the data in AngularJS .
  • As we know that AngularJS is the depends on Javascript so you may find syntax same as JavaScript derived .
  • Normally it will be called by JavaScript Object constructor .

You will be more familiar after executing following code : 



<html>
<script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<body>

<!-- Main Code For Two Inputs   -->
<div ng-app="Manav" ng-controller="Ctrl">
City: 
<input type="text" ng-model="city"><br><br><br>
Country: 
<input type="text" ng-model="country"><br><br><br>
Result: {{city + " " + country}}
</div>
 
<!-- Function Ceated For Two Object -->
<script>
var app = angular.module('Manav', []);
app.controller('Ctrl', function($scope) {
    $scope.city = "Rajkot";
    $scope.country = "India";
});
</script>
 
</body>
</html>

As you can see above example :


We have taken Two inputs for first it's City and another is Country .

After that we have used JavaScript function and it will be called by $scope

Let's see output :

AngularJS Function


Try to run above code and make changes which you want .

Thanks for Reading .


basic asp.net mvc tutorials, Free asp.net mvc Tutorials for beginners, mvc, asp.net mvc, .net tutorials, mvc tutorial, mvc tutorials, asp.net mvc tutorials, mvc tutorial, mvc tutorials for Beginners , asp.net mvc Basics, basic mvc, mvc4, mvc5,.net mvc

Read More