0

am trying to go over AngularJS as a complete n00b, installed everything using Yeoman, grunt and bower.

I have been fiddling around with the code nicely but now am stuck at trying to access parent scope. See Code below

'use strict';

angular.module('castLibraryApp')
  .controller('library', function ($scope) {
    $scope.movies =  [
        {title: 'Sherlock Holmes', poster: 'http://bit.ly/19p8cla'},
        {title: 'Star Trek', poster: 'http://bit.ly/1eAagVa'},
      ];
    $scope.directory  = '~/Movies/';
    console.log($scope.movies);
  })
  .controller('movie', function ($scope, $routeParams) {
    $scope.section  = 'View Movie';
    console.log($scope.movies);
  });

Library controller is called in my main.html template, while the movie controller is accessed in my view.html template. I want to print the information such as name and poster in the view template.

However I keep getting undefined variable

I know it my be a silly error but would really appreciate the help

2 Answers 2

3

you may use $scope.$parent to access your library controller. But this is not a good design. Better you put your movies in service: http://docs.angularjs.org/guide/dev_guide.services.understanding_services

Sign up to request clarification or add additional context in comments.

Comments

2

In movie controller use

$scope.$parent.movies

and in view.html, use

{{ $parent.movies }}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.