Make delicious recipes!

Angular.JS Controller Global Functions


Prior to 1.3 version of Angular.JS, global functions could be specified as controller functions.
Below example shows one such usage.
However, post 1.3, their usage is not recommended and they are not supported by default.

Angular.JS Example (will not work with 1.3 version)

<HTML>
<HEAD>
    <title>Angular.JS Controller - PrismoSkills</title>
    <!-- Link Twitter Bootstrap -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
    <!-- Link Angular.JS -->
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
 
    <script>
        var moduleName = 'store';
        var moduleDependencies = [];
        var app = angular.module(moduleName, moduleDependencies);
        
        function MyFunction($scope)
        {
        	$scope.property1 = {firstName: 'John', lastName: 'Rambo'};
        	$scope.popname = function() {alert ($scope.property1.firstName);}
        }
    </script>
</HEAD>
 
<BODY> 
    <div ng-app="store">
        <div ng-controller="MyFunction" style="border:1px solid black; padding:20px; margin:11px; border-radius:11px; width:300px">
            Hello {{property1.firstName}} {{property1.lastName}}
            <BR><BR>
            <input type="text" ng-model="property1.firstName"/>
            <BR><BR>
            <a href="" ng-click="popname()">popup that name</a>
        </div>
    </div>
</BODY>
</HTML>


Result:

Hello {{property1.firstName}} {{property1.lastName}}



popup that name







Like us on Facebook to remain in touch
with the latest in technology and tutorials!


Got a thought to share or found a
bug in the code?
We'd love to hear from you:

Name:
Email: (Your email is not shared with anybody)
Comment:

Facebook comments:

Site Owner: Sachin Goyal