hi can someone give the right step to rearrange the code??? i need to put every controller in a view because now i have only the controller in app.js and in controller.js for all the views and it is a mess
Hust some advice, some trick to do it in the right way. Thanks
Sometimes, when you are still in the learning-zone, it is better to just start out clean.
Read up on your knowledge of AngularJS, UIRouter and decide first on how you’re gonna structure your project.
Then start a new ionic project and try again…
In your index.html you can setup links to your .js files like so: <script src="js/controllers.js"></script>
Then, in controllers.js, set it up something like this: angular.module('starter.controllers', []) .controller('pageOneCtrl', function($scope,$ionicPlatform, $state, ...whatever) { your controller code... }) .controller('pageTwoCtrl', function($scope,$ionicPlatform, $state, ...whatever) { your controller code... })
Now you can access it through your stateProvider in app.js like so: .state('app', { url: "/app", abstract: true, templateUrl: "templates/app.html" }) .state('app.pageOne', { url: '/pageOne', views: { 'page-one':{ templateUrl: 'templates/pageOne.html', controller: 'pageOneCtrl' } } }) .state('app.pageTwo', { url: '/pageTwo', views: { 'page-two':{ templateUrl: 'templates/pageTwo.html', controller: 'pageTwoCtrl' } } });
As @coreelements also poined out, I recomend strongly to read up on AngularJS an UI-routing since this is pretty basic stuff you should get familiar with first.
you can either have multiple controller files and point to each of them from your index.html,
or have just one controllers.js file and contain all controllers in there. It’s just how you like to structure it.
Ok i’ll do it thank to all…but i need your help again…
i have the login controller in the controller.js it’s call 'AppCtrl’
in another controller ‘odlCtrl’ i have 2 http.get and two query to populate tables and show data in views,
i need to do this get at the login how can i pass function (and data…$rootScope?) between controller???
thanks, but for create service is the same that create controller?? another js file ?? i can have more service?
because i have this one for the auth
angular.module(‘starter.services’, [‘ngCookies’])
.factory(‘Auth’, function ($cookieStore) {
var _user = $cookieStore.get(‘starter.user’);
var setUser = function (user) {
_user = user;
$cookieStore.put(‘starter.user’, _user);
}
Thank you so much…for the next project i’ll use this schema…but for now i need to change a controller into a service, because i make an http get an now the app doesn’t wait for data, because i don’t know jow to use promise, deferred, q… So i need to make this change. I’m in huge trubles!!!