Monday 15 August 2011

javascript - How to change title of page based on drop down menu items in AngularJS -



javascript - How to change title of page based on drop down menu items in AngularJS -

i have html file displays drop downwards menu of categories getting remote database using php script via ajax call. want able alter title of html page name of item click in drop downwards menu. example, if click on heating , cooling in drop downwards menu, want alter title of page 'heating , cooling'. have been googling around answers, far left more confusion. btw doing in angularjs. here html file:

<h2> awesome things </h2> <div ng-controller="mainctrl"> <span class="dropdown" on-toggle="toggled(open)"> <a href class="dropdown-toggle"> click me see awesome things! </a> <ul class="dropdown-menu"> <li ng-repeat="category in categories track $index"> <!--fix expression--> <a href>{{category}}</a> </li> </ul> </span> </div>

here maincontroller file 'main.js':

angular.module('yostartupapp') .controller('mainctrl', function ($scope, $http) { $scope.awesomethings = [ 'html5 boilerplate', 'angularjs', 'karma', 'sitepoint' ]; $scope.status = { isopen: false }; $scope.toggled = function(open) { console.log('dropdown now: ', open); }; $scope.toggledropdown = function($event) { $event.preventdefault(); $event.stoppropagation(); $scope.status.isopen = !$scope.status.isopen; }; //making ajax calls -- current step i'm working on not work!!!! $http.get('http://test.s17.sevacall.com/abhas/index.php'). success(function(data, status, headers, config) { console.log(data);//debug $scope.categories = data; }). error(function(data, status, headers, config) { //log error }); });

any help appreciated! in advance!

this can achieved using plain javascript consider following

<select id="title_select"> <option value="title1">title1</option> <option value="title2">title2</option> <option value="title3">title3</option> <option value="title4">title4</option> <option value="title5">title5</option> </select> <script> document.getelementbyid("title_select").addeventlistener("change",changetitle); function changetitle(){ var titletemp = document.getelementbyid("title_select").value; document.title=titletemp; } </script>

javascript php html angularjs

No comments:

Post a Comment