Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8392637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:33:53+00:00 2026-06-09T19:33:53+00:00

There is a lot of reusable functionality that I have defined in my application

  • 0

There is a lot of reusable functionality that I have defined in my application that EVERY controller uses with the $scope variable. Instead of me having to create a shared service each time, is there a way to extend the $scope variable so that I can have my extended code available everywhere?

Something like:

//I've tested this out and it doesn't work, but this is what I want to do.
angular.module('App',[]).config(['$scopeProvider',function($scope) {
  $scope.method1 = function() { ... };
  $scope.method2 = function() { ... };
}]);

Then later on:

var HomeCtrl = function($scope) {
  $scope.method1();
};

Is this possible? Or do I need to create a shared service and then have the $scope extend from that for the first line of each controller?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:33:54+00:00Added an answer on June 9, 2026 at 7:33 pm

    Instead of .config try .run, this will do exactly what you want.

    angular.module('App', []).run(['$rootScope', function($rootScope) {
      $rootScope.foo = function() {
         alert("WIN!");
      };
    }]);
    
    angular.module('App').controller('HomeCtr', ['$scope', function($scope) {
      $scope.foo(); #will call the alert
    }]);
    

    NOTE I have only used module.controller because I like it, var HomeCtrl = function($scope) { will have the same effect.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an application (Asp.Net MVC) that contains a lot of reusable components.
I have lot of legacy models in MVC application and there are lot of
I know that there are lot of tags in XAML that have simmilar names
I know that there are lot's of questons on this, but all seem to
I see there are lot's of examples in Ext JS where instead of actually
There are a lot of blogs saying that a hasOwnProperty check should be used
There are a lot of iOS apps in the iTunes Store that, upon launch,
Hey there you lot, is there a way that I can open a lightbox
I have some legacy code where there are lot of e.printStackTrace() , those are
as everyone may have noticed, there are lot of fake/rudimentary REST-APIs in the wild

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.