Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49076

How to add controller to side-menu

$
0
0

@Wahtel wrote:

Hi everybody, i faced with the problem that i added ng-controller in my side-menus, and my side-menus is placed in my index.html like this:

<body ng-app="starter">
  <ion-side-menus enable-menu-with-back-views="false" ng-controller="SideMenuCtrl">
    <ion-side-menu-content>
      <ion-nav-bar class="my-bar">
        <ion-nav-back-button id="my-back-button" class="button-clear">
          <i class="ion-chevron-left"></i>
        </ion-nav-back-button>
        <ion-nav-buttons side="left">
          <button class="button button-icon button-clear mybutton bot" menu-toggle="left">
              <i class="my-navicon"></i>
          </button>
        </ion-nav-buttons>
       <ion-nav-title>
          <img class="title-image" src="css/img/extractor-logo.png">
       </ion-nav-title>
      </ion-nav-bar>
      <ion-nav-view></ion-nav-view>
    </ion-side-menu-content>

    <ion-side-menu side="left" class="sidemenu height">
    
      <div>
        <div>
          <a href="#/app/options" class="button button-icon button-clear" menu-toggle="left"><i class="my-gear-icon"></i></a>
        </div>
        <hr class="longhr">
      </div>
      <div class="all-projects"><h3>{{&apos;allProjects&apos; | translate}}</h3></div>
      <div ng-repeat="item in projects">
        <hr class="shorthr">
        <div class="project">
          <i class="custom-icon-{{item.id}} icon-color-assertive my-circle-icon"></i>
          <h3>{{item.title}}</h3>
          <section class="myseaction">
            <label>{{prop.name}}</label>
            <ul type="disc">
              <li>{{val}}</li>
            </ul>
          </section>
        </div>
      </div>
    </ion-side-menu>
</ion-side-menus>
</body>

In this case i've got two problems:

1) my side-menus controller works on every page, in this controller i'm working with my local database, and event like $scope.$on('$ionicView.eneter', function() {}) works not as i want, because it works on every page of my application.
2) the second problem is that, my code works twice everytime, here is my sideMenuCtrl:

extractor.controller('SideMenuCtrl', [
'$scope',
'loginService',
'DataService',
'$ionicPlatform',
'$ionicHistory',
function($scope, loginService, DataService, $ionicPlatform, $ionicHistory) {



var setProjects = function() {
	DataService.getProjectsFromApi();
}; // setProjects

var getProjects = function() {
	DataService.getProjectsFromDB().then(function(res) {
		$scope.projects = res;
		// console.log($scope.projects);
	});
}; // getProjects

$scope.$on('$ionicView.enter', function() {
	setProjects();
	getProjects();
        alert('test'):
});

 }]); // SideMenuCtrl

Don't know how why my code working every time two times, every data sets to the database two times, and displays two times, alerts two times, i'm trying to fix this second day, and have no more ideas, so if you give me some hint, i will be appreciate, THANKS!

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49076

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>