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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:01:15+00:00 2026-06-18T07:01:15+00:00

Background I have the most basic newbie AngularJS question, forgive my ignorance: how do

  • 0

Background

I have the most basic “newbie” AngularJS question, forgive my ignorance: how do I refresh the model via code? I’m sure it’s answered multiple times somewhere, but I simply couldn’t
find it.
I’ve watched some great videos here http://egghead.io and went quickly over the tutorial, but still I feel I’m missing something very basic.

I found one relevant example here ($route.reload()) but I’m not sure I understand how to use it in the example below

Here is the setup

controllers.js

function PersonListCtrl($scope, $http) {
  $http.get('/persons').success(function(data) {
    $scope.persons = data;
  });
}

index.html

...
<div>
    <ul ng-controller="PersonListCtrl">
        <li ng-repeat="person in persons">
            Name: {{person.name}}, Age {{person.age}}
        </li>
    </ul>
</div>
...

This all works amazingly well, each time the page is reloaded I see the list of people as expected

The questions

  1. Let’s say I want to implement a refresh button, how do I tell the model to reload programmatically?
  2. How can I access the model? it seems Angular is magically instantiating an instance of my controller, but how do I get my hands on it?
  3. EDIT added a third question, same as #1 but how can it be done purely via JavaScript?

I’m sure I’m missing something basic, but after spending an hour trying to figure it out, I think it deserves a question. Please let me know if it’s duplicate and I’ll close + link to it.

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

    You’re half way there on your own. To implement a refresh, you’d just wrap what you already have in a function on the scope:

    function PersonListCtrl($scope, $http) {
      $scope.loadData = function () {
         $http.get('/persons').success(function(data) {
           $scope.persons = data;
         });
      };
    
      //initial load
      $scope.loadData();
    }
    

    then in your markup

    <div ng-controller="PersonListCtrl">
        <ul>
            <li ng-repeat="person in persons">
                Name: {{person.name}}, Age {{person.age}}
            </li>
        </ul>
       <button ng-click="loadData()">Refresh</button>
    </div>
    

    As far as “accessing your model”, all you’d need to do is access that $scope.persons array in your controller:

    for example (just puedo code) in your controller:

    $scope.addPerson = function() {
         $scope.persons.push({ name: 'Test Monkey' });
    };
    

    Then you could use that in your view or whatever you’d want to do.

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

Sidebar

Related Questions

I have the most basic PHP code with just these 13 lines: <!DOCTYPE html>
I have a scroll view with transparent background that covers most of the screen.
Background: I have an MVC based polaroid object. The model keeps the photo's metadata,
I have a pretty good non-OOP background. I've done lots of Visual Basic coding,
Basic Question: I have a k dimensional box. I have a vector of upper
I have some very basic code and it works except everything aligns to the
Background I have an array of objects (Users) defined and set as follows: //
Background I have two lists, the first is items which contains around 250 tuples,
Background I have a function that takes a config object as an argument. Within
Background : I have a few different threads which each need to write to

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.