Controller Being Called Twice In Ionic (angularjs)
Solution 1:
If you are using ui-router
you don't have to use ng-controller
. You have used it in your dashboard.html, another is generated by ui-router
- that's why it is hit twice.
Solution 2:
Ok so after a long time debugging and check stuff out, I found out that it was an issue relating to the Nav Bar in ionic, essentially, I was calling <ui-view></ui-view>
& <ion-nav-view></ion-nav-view>
on the same page, so basically doubling up on my views which in turn was calling the controller twice.
Solution 3:
I know this has been answered already as well, but I wanted to add my fix for the exact same problem.
My controllers were also being called twice, but in my case I had to comment out the ng-controller
settings in various files:
My config function in the main app.js
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('splash', {
url: "/",
templateUrl: "app/splash/splash.html"// controller: 'SplashCtrl'
})
Since I was already calling it in the markup:
<ion-viewview-title="TickerTags"ng-controller="SplashCtrl as splash"><ion-contentclass="splash">
The controller key inside of my Directives
angular
.module('tagsPanelDirective', [])
.controller('TagsPanelCtrl', TagsPanelCtrl)
.directive('tagsPanel', tagsPanel);
functiontagsPanel() {
var directive = {
templateUrl: "app/tags/tagsPanel.html",
restrict: "E",
replace: true,
bindToController: true,
// controller: 'TagsPanelCtrl as tagsPanel',
link: link,
scope: false
};
return directive;
functionlink(scope, element, attrs) {}
}
Again since I was already calling it from within the template markup:
<section class="tags-panel" ng-controller="TagsPanelCtrl as tagsPanel">
Post a Comment for "Controller Being Called Twice In Ionic (angularjs)"