Reputation: 397
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
Upvotes: 0
Views: 1792
Reputation: 672
In movie controller use
$scope.$parent.movies
and in view.html, use
{{ $parent.movies }}
Upvotes: 2
Reputation: 16341
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
Upvotes: 3