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)

    <title>Angular.JS Controller - PrismoSkills</title>
    <!-- Link Twitter Bootstrap -->
    <link rel="stylesheet" href="">
    <!-- Link Angular.JS -->
    <script src=""></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);}
    <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}}
            <input type="text" ng-model="property1.firstName"/>
            <a href="" ng-click="popname()">popup that name</a>


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:

Email: (Your email is not shared with anybody)

Facebook comments:

Site Owner: Sachin Goyal