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

  • SEARCH
  • Home
  • 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 8505793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:25:13+00:00 2026-06-11T02:25:13+00:00

I am trying to move bits from a parent controller inside child controllers in

  • 0

I am trying to move bits from a parent controller inside child controllers in an angularjs app to not pollute the main controller too much.
Here’s a simplified fiddle: http://jsfiddle.net/terebentina/5RMPV/
So when I click the change button, the third letter should change to ‘X’.
Initially the item_change() function was inside the main controller and was doing $scope.items[idx] = 'X' and this worked just fine. However, since I moved it inside the ItemCtrl, I have no idea how to access it for the 3rd element.

Any help would be much appreciated.

  • 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-11T02:25:15+00:00Added an answer on June 11, 2026 at 2:25 am

    One way to move things out of your main controller is to share and make all changes to the data between controllers inside a service or factory (described pretty nicely in this article).

    Here is an updated fiddle. You would just need to inject the itemsService into any controller you would want to access the items data in.

    angular.module('test', [])
        .service('itemsService', function(){
            var items = ['A', 'B', 'C', 'D'];
    
            return{
                getItems: function(){
                    return items;
                },
                changeItem: function(index, value){
                    items[index] = value;
                }
            }
        })
        .controller('MainCtrl', function($scope, itemsService) {
            $scope.items = itemsService.getItems();       
    
            $scope.change = function(idx) {
                itemsService.changeItem(idx, 'X');
            }
    
        })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While trying to move an axis2 web-app from glassfish3 to tomcat6, I can't seem
I am trying to move sql functionality from my app to xml, so the
I'm trying to move a former app from windows mobile to iphone. Any ideas
I am trying to move the logic to the very high-level from the db.
I am trying to move to UITableView named Cart from UIView by clicking on
I am trying to move from MySQL to MySQLi but am having some problems.
So I am trying to move selected rows from 1 table to another in
I'm trying to move a file from one directory to another (in SD Card)
I'm trying to move an app to rails 3.1. Many of my tests break,
I'm trying to move over some fish species information profiles from a bespoke CMS

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.