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 8436323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:08:59+00:00 2026-06-10T07:08:59+00:00

In angularjs, we define our controllers into window . While this would not create

  • 0

In angularjs, we define our controllers into window. While this would not create name clashes with other js modules and plugins, it is still not a good practise: a single application should expose a single object to the global namespace.

This is the usual way, defined in window:

function UserController($scope) { ... }

HTML:

<div ng-controller="UserController">

This is what I think of:

myApp.UserController = function ($scope) { ... };

So in that case, I should be initiating controller from html like this

<div ng-controller="myApp.UserController">

What do you think?

  • 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-10T07:09:01+00:00Added an answer on June 10, 2026 at 7:09 am

    One of the ways around it is to define it within Angular itself such as the way you described. In other words:

    angular.module('YourApp').controller('ControllerName', function($scope) {})

    I have confirmed the above method doesn’t pollute the global namespace.

    Edit: You also don’t need to use <div ng-controller="myApp.UserController"> as you could define myApp in the attribute ng-app: <body ng-app="myApp"> That way you could call the ng-controller without prefixing myApp every time.

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

Sidebar

Related Questions

I'm trying to create my first app with AngularJS. It looks neat, but there's
I'm new to angularjs and python and I have this problem. I've been trying
I've recently been using Angularjs in my project. I'm trying to create a dynamic
It seems that AngularJS really puts an heavy emphasis on using filters and other
How would I use AngularJS ng-repeat to display the following HTML (Twitter Bootstrap Scaffolding)?
How do you do a ternary with AngularJS (in the templates)? It would be
I am using AngularJS 1.0, PHP, and mysql with localhost on my Mac. I
I am working with AngularJS for my latest project. In the documentation and tutorials
I want to use AngularJS with Django however they both use {{ }} as
I have an AngularJS page with several form inputs. When the some of the

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.