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!!!