My AngularJS view is able to access it's controller's scope, but ng-repeat doesn't work

saila

I'm building a MEAN app and used yeoman to scaffold the client side code. I have a controller and view called movies.

Here is the movie controller:

'use strict';

/**                                                                                                                                                                                  
 * @ngdoc function                                                                                                                                                                   
 * @name clientApp.controller:MoviesCtrl                                                                                                                                             
 * @description                                                                                                                                                                      
 * # MoviesCtrl                                                                                                                                                                      
 * Controller of the clientApp                                                                                                                                                       
 */
angular.module('clientApp')
  .controller('MoviesCtrl', function () {
      this.movies = [
          {
              title: 'A New Hope',
              url: 'http://youtube.com/embed/1g3_CFmnU7k'
          },
          {
              title: 'The Empire Strikes Back',
              url: 'http://youtube.com/embed/96v4XraJEPI'
          },
          {
              title: 'Return of the Jedi',
              url: 'http://youtube.com/embed/5UfA_aKBGMc'
          }
      ];

  });

Here is the movie view:

<table class="table table-striped">
  <thead>
    <th>Title</th>
    <th>URL</th>
  </thead>
  <tbody>
    <tr ng-repeat="movie in movies">
      <td>{{movie.title}}</td>
      <td>{{movie.url}}</td>
    </tr>
  </tbody>
</table>
{{movies}}

When I view the page in my browser, the ng-repeat doesn't work (nothing is printed out), but where I explicitly print out {{movies}} in the view, I see the movies json that I defined in the controller. So, I know that the view has access to the controller's scope.

Why isn't ng-repeat working even when the view has access to the controller's scope?

Felix

In order to use this.movies, you need to use controller AS syntax (MovieCtrl as ctrl). Even so, you may run into problems if you don't save controller object (e.g., vm = this)

The way you have it now, you need to assign to $scope instead of this

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

My AngularJS view is able to access it's controller's scope, but ng-repeat doesn't work

From Dev

Why my form doesn't work when it's inside of ng-repeat?

From Dev

Access ng-repeat's item scope

From Dev

AngularJS ng-repeat doesn't work

From Dev

AngularJS ng-repeat doesn't work

From Dev

AngularJS: unable to access scope variable after ng-repeat in view

From Dev

Ng-view in AngularJS doesn't work

From Dev

Angular $compile on scope with ng-repeat doesn't work

From Dev

Angular ng-repeat doesn't work in child controller

From Dev

directive's scope inside ng-repeat angularjs

From Dev

AngularJS ng-repeat: view doesn't update on model change…

From Dev

Angularjs OrderBy on ng-repeat doesn't work

From Dev

AngularJS : directive ng-repeat doesn't work in link function

From Dev

ng-repeat doesn't work with data in my case

From Dev

Not able to access controller variables on view using {{}} in angularjs

From Dev

AngularJS - Scope not applied in view within controller's function

From Dev

AngularJS - Scope not applied in view within controller's function

From Dev

AngularJS data-ng-controller doesn't work

From Dev

AngularJS data-ng-controller doesn't work

From Dev

Getting ng-repeat to work inside of AngularJS's $interpolate service

From Dev

Getting ng-repeat to work inside of AngularJS's $interpolate service

From Dev

ng-view doesn't show anything in my angularJS app

From Dev

Angular - changes to directive controller's scope aren't reflected in view

From Dev

How to access to the controller scope from a directive inside ng-repeat?

From Dev

nested ng-repeat doesn't work

From Dev

nested ng-repeat doesn't work

From Dev

ng-repeat doesn't work properly

From Dev

AngularJs - access scope variable in ng-repeat with same name

From Dev

AngularJs - access scope variable in ng-repeat with same name

Related Related

  1. 1

    My AngularJS view is able to access it's controller's scope, but ng-repeat doesn't work

  2. 2

    Why my form doesn't work when it's inside of ng-repeat?

  3. 3

    Access ng-repeat's item scope

  4. 4

    AngularJS ng-repeat doesn't work

  5. 5

    AngularJS ng-repeat doesn't work

  6. 6

    AngularJS: unable to access scope variable after ng-repeat in view

  7. 7

    Ng-view in AngularJS doesn't work

  8. 8

    Angular $compile on scope with ng-repeat doesn't work

  9. 9

    Angular ng-repeat doesn't work in child controller

  10. 10

    directive's scope inside ng-repeat angularjs

  11. 11

    AngularJS ng-repeat: view doesn't update on model change…

  12. 12

    Angularjs OrderBy on ng-repeat doesn't work

  13. 13

    AngularJS : directive ng-repeat doesn't work in link function

  14. 14

    ng-repeat doesn't work with data in my case

  15. 15

    Not able to access controller variables on view using {{}} in angularjs

  16. 16

    AngularJS - Scope not applied in view within controller's function

  17. 17

    AngularJS - Scope not applied in view within controller's function

  18. 18

    AngularJS data-ng-controller doesn't work

  19. 19

    AngularJS data-ng-controller doesn't work

  20. 20

    Getting ng-repeat to work inside of AngularJS's $interpolate service

  21. 21

    Getting ng-repeat to work inside of AngularJS's $interpolate service

  22. 22

    ng-view doesn't show anything in my angularJS app

  23. 23

    Angular - changes to directive controller's scope aren't reflected in view

  24. 24

    How to access to the controller scope from a directive inside ng-repeat?

  25. 25

    nested ng-repeat doesn't work

  26. 26

    nested ng-repeat doesn't work

  27. 27

    ng-repeat doesn't work properly

  28. 28

    AngularJs - access scope variable in ng-repeat with same name

  29. 29

    AngularJs - access scope variable in ng-repeat with same name

HotTag

Archive