javascript - Scope variable not printing AngularJS -
i starting build first single page application in angularjs , stuck on simple problem. want able set scope variables 'title' , 'subtitle' change page header each time user clicks 'link'. on main index page, html should displaying looks this:
<div id="header"> <h1>{{title}}</h1> <h3>{{subtitle}}</h3> </div>
in app.js file doing of routing, have multiple controllers applied depending on url. each of controllers looks this:
app.controller('displayctrl', function($scope, $http) { $scope.title = "machine profiles"; $scope.subtitle = "add, remove, , view data machines"; console.log($scope.title); });
as can see outputting console variable set, , displaying correct thing. problem h1 , h3 tags not displaying scope variable! title , subtitle in header blank, though scope variable being set , logged. not getting errors in console on page load or when click links. 'templateurl' loading in routeprovider displaying content on of partial pages in main container well. titles broken. please help. in advance
is <div id="header">
outside of ng-view
?
if - means <div id="header">
outside of displayctrl
's scope.
try updating $rootscope
instead of $scope
.
app.controller('displayctrl', function($scope, $rootscope, $http) { $rootscope.title = "machine profiles"; $rootscope.subtitle = "add, remove, , view data machines"; });
make sure <div id="header">
inside ng-app
.
Comments
Post a Comment