i am building an Mobile App using ONSEN UI. I am using angularjs as supporting JavaScript framework.
Here is how i have 2 views in a single page template.
<ons-template id="categories.html">
<ons-page ng-controller="directoryControl">
<ons-toolbar>
<div class="center">Directory Category List</div>
</ons-toolbar>
<ons-list>
<ons-list-item modifier="chevron" class="list-item-container" ng-repeat="PostCategory in PostCategories">
<ons-row ng-click="setCurrentCategory(PostCategory.slug); menu.setMainPage('directory-page.html')">
<ons-col>
<div class="name">
{{PostCategory.title}}
</div>
</ons-col>
<ons-col width="40px"></ons-col>
</ons-row>
</ons-list-item>
</ons-list>
</ons-page>
</ons-template>
<!-- when i click on any row (List Item) -->
<ons-template id="directory-page.html">
<ons-page ng-controller="directoryCategoryListing">
<ons-toolbar>
<div class="center">Directory List</div>
</ons-toolbar>
<p style="text-align: center" ng-show="spinner">
<ons-icon icon="spinner" class="spinner center" size="40px" spin="true" fixed-width="true" ></ons-icon>
</p>
<ons-list>
<ons-list-item modifier="chevron" class="list-item-container">
<ons-row>
<ons-col width="95px">
<img src="images/location1.png" class="thumbnail">
</ons-col>
<ons-col>
<div class="name">
Some Title
</div>
<div class="desc">
Some Description
</div>
</ons-col>
<ons-col width="40px"></ons-col>
</ons-row>
</ons-list-item>
</ons-list>
</ons-page>
</ons-template>
So here is my controllers looks like:
var module = angular.module('app', ['onsen']);
module.controller('directoryControl', function($scope, $http) {
ons.ready(function() {
$scope.spinner = true;
$scope.CurrentCategory = null;
//some other code in between
$scope.setCurrentCategory = function(categoryName){
$scope.CurrentCategory = categoryName;
console.log($scope.CurrentCategory);
}
});
});
/* Second CONTROLLER WHERE I WANT $scope.CurrentCategory value */
module.controller('directoryCategoryListing', function($scope, $http) {
ons.ready(function() {
console.log($scope.CurrentCategory);
});
});
I can get the value of clicked row(list item) in the first controller. But couldn't take it to second one. Is there any way i can do that?
The template structure is one page style. http://codepen.io/anon/pen/wavYzY for reference
Thank you! (In advance)