$new() or $rootScope.new() in angularjs

Are AngularJs controllers singletons ?

AngularJs code-sample

var app = angular.module('singletonApp', []);

app.controller('singletonTest', function ($scope, singletonService) {
    $scope.name = singletonService.getValue();
});

app.service('singletonService', function () {
    var field = {
        value: 'hello Anil'
    };
    var getValue = function () {
        return val;
    }
    return {
        getValue: getValue
    };
});

HTML code

<div ng-app="singletonApp">
    <div ng-controller="singletonTest">
            <input type="text" ng-model="name.value" />
    </div>
</div>




ANIL SINGH

Hey! I'm Anil Singh. I author this blog. I'm Active Blogger, Programmer. I love learning new technologies, programming, blogging and participating the forum discussions more...
My Blogs - http://www.code-sample.com and http://www.code-sample.xyz
My Books - Buy Books Online at Best Prices

You Might Also Like
Post a Comment
www.code-sample.com/. Powered by Blogger.