The Google Map doesn't appear working with Ionic and AngularJS - angularjs

The Google Map doesn't appear. I work with Ionic and AngularJS and I use the Geolocation plugin.
This is my routing for the app:
angular.module('app.routes', [])
.config(function($stateProvider, $urlRouterProvider) {
// Ionic uses AngularUI Router which uses the concept of states
// Learn more here: https://github.com/angular-ui/ui-router
// Set up the various states which the app can be in.
// Each state's controller can be found in controllers.js
$stateProvider
.state('menu.rServation', {
url: '/Réservation',
views: {
'side-menu21': {
templateUrl: 'templates/rServation.html',
controller: 'rServationCtrl'
}
}
})
.state('menu.voiture', {
url: '/Voiture',
views: {
'side-menu21': {
templateUrl: 'templates/voiture.html',
controller: 'voitureCtrl'
}
}
})
.state('menu.paramTres', {
url: '/Paramètres',
views: {
'side-menu21': {
templateUrl: 'templates/paramTres.html',
controller: 'paramTresCtrl'
}
}
})
.state('menu.LocationMap', {
url: '/Location',
views: {
'side-menu21': {
templateUrl: 'templates/Locationmap.html',
controller: 'LocationMapCtrl'
}
}
})
.state('menu.LocationMMap', {
url: '/Locationn',
views: {
'side-menu21': {
templateUrl: 'templates/LocationMMap.html',
controller: 'MapCtrl'
}
}
})
.state('menu.login', {
url: '/Login',
views: {
'side-menu21': {
templateUrl: 'templates/login.html',
controller: 'loginCtrl'
}
}
})
.state('menu', {
url: '/side-menu21',
templateUrl: 'templates/menu.html',
abstract:true
})
.state('menu.detailsVoiture', {
url: '/Voiture/:Id',
views: {
'side-menu21': {
templateUrl: 'templates/detailsVoiture.html',
controller: 'voitureCtrl'
}
}
})
.state('menu.conexion', {
url: '/Conexion',
views: {
'side-menu21': {
templateUrl: 'templates/conexion.html',
controller: 'conexionCtrl'
}
}
})
.state('menu.detailsPreReservation',{
url: '/DetailsPreReservation',
views: {
'side-menu21': {
templateUrl: 'templates/detailsPreReservation.html',
controller: 'detailsPreReservationCtrl'
}
}
})
.state('menu.profile',{
url: '/profile',
views: {
'side-menu21': {
templateUrl: 'templates/profil.html',
controller: 'profilCtrl'
}
}
})
$urlRouterProvider.otherwise('/side-menu21/Réservation')
});
and this is mu controller
.controller('MapCtrl', function($scope, $state, $cordovaGeolocation) {
var options = {timeout: 10000, enableHighAccuracy: true};
$cordovaGeolocation.getCurrentPosition(options).then(function(position){
var latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var mapOptions = {
center: latLng,
zoom: 15,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
$scope.map = new google.maps.Map(document.getElementById("map"), mapOptions);
}, function(error){
console.log("Could not get location");
});
})
and this my view:
<ion-view>
<ion-content>
<div id="map" data-tap-disabled="true"></div>
</ion-content>
</ion-view>
and this my menu.html for side menu:
<ion-side-menus enable-menu-with-back-views="false">
<ion-side-menu-content>
<ion-nav-bar class="bar-calm">
<ion-nav-back-button></ion-nav-back-button>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left"></button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="side-menu21"></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="left" id="side-menu21">
<ion-header-bar class="bar-calm">
<div class="title">Menu</div>
</ion-header-bar>
<ion-content padding="false" class="side-menu-left has-header">
<ion-list>
<ion-item ui-sref="menu.rServation" menu-close="" >
<i class="icon ion-home balanced ">Réservation</i>
</ion-item>
<ion-item ui-sref="menu.voiture" menu-close="" >
<i class="icon ion-model-s balanced">Voitures</i>
</ion-item>
<ion-item ui-sref="menu.paramTres" menu-close="" >
<i class="icon ion-android-settings balanced">Paramètres</i>
</ion-item>
<ion-item ui-sref="menu.LocationMap" menu-close="" >
<i class="icon ion-map balanced">Location Agence</i>
</ion-item>
<ion-item ui-sref="menu.LocationMMap" menu-close="" >
<i class="icon ion-map balanced">Locationn Agence</i>
</ion-item>
<ion-item ui-sref="menu.login" menu-close="" >
<i class="icon ion-log-in balanced">Login</i>
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
This is an image for the template and no error

You didn't set the height for the container:
<style>
#map {
height: 400px;
}
</style>

Related

Ionic Page Navigation is not working

Ionic sidemenu default app created and map and markerClick tow page was add ed in menu list. Map is working fine but MarkerClick is not. When click on MarkerClick form sidemenu this redirect on last active page.
menu.html
<ion-side-menu side="left">
<ion-header-bar class="bar-stable">
<h1 class="title">Left</h1>
</ion-header-bar>
<ion-content>
<ion-list>
<ion-item menu-close ng-click="login()">
Login
</ion-item>
<ion-item menu-close href="#/app/search">
Search
</ion-item>
<ion-item menu-close href="#/app/browse">
Browse
</ion-item>
<ion-item menu-close href="#/app/playlists">
Playlists
</ion-item>
<ion-item menu-close href="#/app/map">
Map
</ion-item>
<ion-item menu-close href="#/app/markerClick">
Marker
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
app.js
.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app', {
url: '/app',
abstract: true,
templateUrl: 'templates/menu.html',
controller: 'AppCtrl'
})
.state('app.search', {
url: '/search',
views: {
'menuContent': {
templateUrl: 'templates/search.html'
}
}
})
.state('app.browse', {
url: '/browse',
views: {
'menuContent': {
templateUrl: 'templates/browse.html'
}
}
})
.state('app.playlists', {
url: '/playlists',
views: {
'menuContent': {
templateUrl: 'templates/playlists.html',
controller: 'PlaylistsCtrl'
}
}
})
.state('app.single', {
url: '/playlists/:playlistId',
views: {
'menuContent': {
templateUrl: 'templates/playlist.html',
controller: 'PlaylistCtrl'
}
}
})
.state('app.map', {
url: '/map',
views: {
'menuContent': {
templateUrl: 'templates/map.html',
controller: 'MapCtrl'
}
}
})
.state('app.markerClick', {
url: '/markerClick',
view: {
'menuContent': {
//templateUrl: '<h1>what the hello</h1>',
templateUrl: 'templates/testTemplate.html',
controller: 'markerClickCtr'
}
}
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app/map');
});
enter image description here
enter image description here
Try to replace href with ui-sref="app.markerClick"
UI-Router provides ui-sref which allows to link to states. This is different than linking to a normal URL. When using UI-Router you want to link to a state, not a URL.

Hide ion items in side menu after login in Ionic/AngularJs

i'm new in Angular and Ionic. I'm trying to hide some ion items from the side menu based on the login status but it doesn't work. Do you know why?
This is the app.js file - it's basicly the default app.js file from the ionic side menu template.
angular.module('starter', ['ionic', 'starter.controllers'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider, $ionicConfigProvider) {
$ionicConfigProvider.tabs.position('top');
$stateProvider.state('app', {
url: '/app',
abstract: true,
templateUrl: 'templates/menu.html',
controller: 'AppCtrl'
});
$stateProvider.state('app.dashboard', {
url: '/dashboard',
views: {
'menuContent': {
templateUrl: 'templates/dashboard.html',
controller: 'AppCtrl'
}
}
});
$stateProvider.state('app.login', {
url: '/login',
views: {
'menuContent': {
templateUrl: './templates/login.html',
controller: 'AppCtrl'
}
}
});
$stateProvider.state('app.single', {
url: '/playlists/:playlistId',
views: {
'menuContent': {
templateUrl: 'templates/playlist.html',
controller: 'PlaylistCtrl'
}
}
});
$urlRouterProvider.otherwise('/app/login');
});
This is the controllers file - After the login form is submitted and
it passes the validation it will call loginSuccess() function which
will set the "isLogged" variable to true. Now the side menu elements
which have ng-show attributes should appear but they don't. If i
insert a console.log in the loginSuccess function it will show that
the variable has the value true but still it doesn't work.
(function() {
'use strict';
var app = angular.module('starter.controllers', []);
app.controller('AppCtrl', function ($scope, $ionicModal, $timeout, $state) {
$scope.bothErrors = false;
$scope.emailError = false;
$scope.isLogged = false;
$scope.loginData = {};
$scope.doLogin = function () {
if($scope.validateEmail($scope.loginData.username)) {
if($scope.loginData.username == 'george#wgeorge.ro' && $scope.loginData.password == '1234') {
$scope.loginSuccess();
}else{
$scope.bothErrors = true;
$scope.emailError = false;
}
}else{
$scope.emailError = true;
}
};
$scope.loginSuccess = function () {
$state.go('app.dashboard');
$scope.bothErrors = false;
$scope.isLogged = !$scope.isLogged;
};
$scope.logOut = function(){
$scope.isLogged = !$scope.isLogged;
$state.go('app.login');
};
$scope.validateEmail = function (email) {
var re = /^(([^<>()\[\]\\.,;:\s#"]+(\.[^<>()\[\]\\.,;:\s#"]+)*)|(".+"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
};
});
}());
This is the sidemenu html file
<ion-side-menus enable-menu-with-back-views="false">
<ion-side-menu-content>
<ion-nav-bar class="bar-stable">
<ion-nav-back-button></ion-nav-back-button>
<ion-nav-title>
<img src="img/logo.png" class="logo">
</ion-nav-title>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left"></button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="menuContent"></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="left">
<ion-content>
<ion-list>
<ion-item menu-close href="#/app/dashboard">
Acasa
</ion-item>
<ion-item ng-show="showProfile" menu-close href="#/app/playlists">
item1
</ion-item>
<ion-item menu-close href="#/app/playlists">
item2
</ion-item>
<ion-item menu-close href="#/app/playlists">
item3
</ion-item>
<ion-item ng-show="isLogged" menu-close href="#/app/playlists">
item4
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>

Ionic and Angular: Routing not working

I have an Ionic sidemenu project with the following menu:
<ion-side-menus enable-menu-with-back-views="false">
<ion-side-menu-content>
<ion-nav-bar class="bar-stable" align-title="center">
<ion-nav-back-button>
</ion-nav-back-button>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left">
</button>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="menuContent"></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="left">
<ion-content>
<div class="list">
<a class="item item-icon-left" menu-close href="#/app/products">
<i class="icon ion-home"></i>
<h2>Home</h2>
</a>
<a class="item item-icon-left" menu-close href="#/app/account">
<i class="icon ion-person"></i>
<h2>mein Konto</h2>
</a>
<a class="item item-icon-left" menu-close href="#/app/orders">
<i class="icon ion-android-list"></i>
<h2>meine Bestellungen</h2>
</a>
</div>
</ion-content>
</ion-side-menu>
</ion-side-menus>
The hrefs defined here are all working as intended.
My products page now has several sub-pages.
Html-File:
<ion-view view-title="Home">
<ion-content>
<ion-list>
<ion-item ng-repeat="product in products" href="#/app/products/{{product.templateUrl}}">
{{product.name}}
</ion-item>
</ion-list>
</ion-content>
</ion-view>
JS-File:
angular.module('App.Products', ['App.Products.Prints', 'App.Products.Box', 'App.Products.Book', 'App.Products.Framed'])
.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider.state('app.products', {
url: "/products",
views: {
'menuContent': {
templateUrl: "modules/products/products.html",
controller: 'ProductsController'
}
}
});
})
.controller('ProductsController', function ($scope, ProductsFactory) {
$scope.products = [];
init();
function init() {
$scope.products = ProductsFactory.getProducts();
}
})
.factory('ProductsFactory', function() {
var products = [
{
name: 'Prints',
img: 'img/wardwarz.png',
templateUrl: 'prints'
},
{
name: 'PhotoBox',
img: 'img/argo.png',
templateUrl: 'box'
},
{
name: 'Photobuch',
img: 'img/django.png',
templateUrl: 'book'
},
{
name: 'Photo im Rahmen',
img: 'img/ic_profile.png',
templateUrl: 'framed'
}
];
var factory = {};
factory.getProducts = function () {
// Hier könnte ein HTTP Request rein um die Produkte vom Server zu erhalten!
return products;
}
return factory;
});
and to show one example one content of a sub page:
Html-File:
<ion-view view-title="Prints">
<ion-content>
</ion-content>
</ion-view>
JS-File:
angular.module('App.Products.Prints', [])
.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider.state('app.products.prints', {
url: "/products/prints",
views: {
'menuContent': {
templateUrl: "modules/products/prints/prints.html"
}
}
});
});
When i now start the app ionic serve the navigation of the sidemenu works fine and i can open my products page. The navigation to prodcuts/prints does not work. I dont get an error message or anything. There is just nothing happening after the click on the item.
Whats going worng here?
An example Project can be found here: Mega File - MyApp.rar
Instead of using only href to do your navigation use
ui-sref="name_of_the_state"
Example:
ui-sref="app.products.prints"
This way you will not have issues with your navigation on angular/ionic.
If you even have a parameter in your route, like:
$stateProvider.state('app.products.edit', {
url: "/products/edit/:id",
views: {
'menuContent': {
templateUrl: "modules/products/prints/prints.html"
}
}
});
you can use:
ui-sref="app.products.edit(1)"
Also, I'm not seeying an abstract route on this, the app. It should be like:
app -> abstract
app.products
app.products.prints
I was able to simulate the error on my PC.
When you work with nested states you like app.products.print you need a intermediary view like this:
Example from a code I have on my pc that is working:
.state("admin", {
url: "/admin",
abstract: true,
views: {
"body": { templateUrl: "partials/_layoutAdmin.html" }
}
})
.state("admin.page", {
url: "/page/:idEdition",
abstract: true,
views: {
"header": { templateUrl: "partials/header.html", controller: "DefaultHeaderController" },
"content": { templateUrl: "partials/_layoutAdminEdition.html" }
}
})
.state("admin.page.create", {
url: "/create",
views: {
"content": { templateUrl: "partials/admin.page.form.html", controller: "PageFormController" }
}
})
Example of Templates
The main layout has thi
<div data-ui-view="body"></div>
The _layoutAdmin has this one
<header data-ui-view="header"></header>
<div class="container-fluid">
<div class="row">
<div data-ui-view="content"></div>
</div>
</div>
When the code enters the admin state it will load this first piece...
THEN...
<div data-ui-view="content" class="edition-form"></div>
AND THEN... the form CODE
So, in your case, you have app.products.prints:
app -> need a view -> ok you got it
app.products -> also need a view -> ok you got it
app.products.prints -> inside app.products view (products.html) you need a to show this inside it.
For simplicity, I suggest you to change it's name to app.productsPrint (without the "." and you'll be able to do it the way you are doing it right now with no impact.
Made some changes on the code you provided:
<ion-view view-title="Home">
<ion-content>
<div ui-view="myTestContent"></div>
</ion-content>
</ion-view>
Notice the ui-view="myTestContent"
and
.state('app.products.prints', {
url: "/prints",
views: {
'myTestContent': {
templateUrl: "modules/products/prints/prints.html"
}
}
});
and it worked.
So, in your case I recommend you to use productPrints instead of products.print. This nesting is used in those view inside view scenarios.

How to ng-hide login button after successful login Ionic?

I have started sideMenu app in ionic and tried some implementation. Initially, ionicModal is used to show login so i change it with ion-list item like;
<ion-side-menu side="left" >
<ion-header-bar class="bar-stable bar-dark">
<a ng-click="redirectToWeb()" > <h1 class="title">NerdApp</h1></a>
</ion-header-bar>
<ion-content >
<ion-list class="BGcolorDG">
<ion-item nav-clear menu-close class="BGcolorDG item item-icon-left item-content-modified" href="#/app/login" ng-show="control.showLogin" > <!--ng-click="login()" -->
<i class="icon ion-locked"></i> <span>Login</span>
</ion-item>
<ion-item nav-clear menu-close href="#/app/search" class="item item-icon-left BGcolorDG item-content-modified">
<i class="icon ion-search"></i><span>Search</span>
</ion-item>
<ion-item nav-clear menu-close href="#/app/browse" class="item item-icon-left BGcolorDG item-content-modified">
<i class="icon ion-ios-browsers"></i><span>Browse</span>
</ion-item>
<ion-item nav-clear menu-close href="#/app/playlists" class="item item-icon-left BGcolorDG item-content-modified">
<i class="icon ion-music-note"></i> <span>Playlists</span>
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
and provide routeState as
state('app', {
url: "/app",
abstract: true,
templateUrl: "templates/menu.html",
controller: 'AppCtrl'
})
.state('app.login', {
url: "/login",
views: {
'menuContent': {
templateUrl: "templates/login.html",
controller: "LoginCtrl"
}
}
})
.state('app.home', {
url: "/home",
views: {
'menuContent': {
templateUrl: "templates/home.html",
controller: "HomeCtrl"
}
}
})
And default route to home controller.
$urlRouterProvider.otherwise('/app/home');
the app controller is as
.controller('AppCtrl', function($scope,$timeout,$location,$rootScope) {
$scope.control = {
showLogin:true
};
if($rootScope.showLogin != undefined && $rootScope.showLogin == false){
$scope.control.showLogin = false;
}
})
Inside loginControl i am checking and redirecting it back to home controller as
$scope.login = function() {
if ($scope.loginData.username == 'hassaan' && $scope.loginData.password == 'khan') {
$rootScope.showLogin = false;
// $location.path('#/app');
$state.go('app.home');
}else{
alert('Incorrect credentials');
}
}
i have tried both $location.path and $state.go and what its doing is redirecting to home page but 'not showing the sidemenu' and when i inspect in browser it showing sidemenu hidden.
The flow images of test app is as
Try use $rootScope
pass it to AppCtrl
.controller('AppCtrl', function (...., $rootScope) {
// and then
$rootScope.control = {
showProfile: false
};
after success authentication - make it true
$rootScope.control = {
showProfile: true
};
now it should work as you expected
Don't use $rootscop if you dont need to.
You can send variables to other controllers with the router from angular using params.
.state('menu.employeeInfo', {
url: '/employeeInfo',
views: {
'side-menu21': {
templateUrl: 'templates/employeeInfo.html',
controller: 'employeeInfoCtrl'
}
},
params: {
appointmentObj: null,
subassignmentObj: null
}
})
You can then pass these vars in the following manner.
$scope.gotoAppointment = function (Appointment, Subassignment) {
$state.go('menu.employeeInfo', { appointmentObj: Appointment, subassignmentObj: Subassignment }, { reload: true });
}

Back Navigation Button not showing

I'm new to Ionic / Angularjs and learning to use it.
I'm fetching menu links from server and on clicking, it goes to detail page but Back button not showing. It is working in Tab Menu example from ionic.
Also when i click browser Back Button, it shows on Homepage (I don't think it should show?)
Could anyone tell me what's wrong?
Codes are as below:
Controller.js
angular.module('GAC.controllers', [])
.controller('AppCtrl', function($scope, pagesService) {
//GET PAGE LIST
pagesService.fetchFromServer().then( function(list){
$scope.pageList = list;
});
})
.controller('PageCtrl', function($scope, $stateParams, pagesService) {
if(!isNaN(parseInt($stateParams.pageId))){
pagesService.fetchById( $stateParams.pageId ).then(function(page){
$scope.page = page;
});
}else{
alert('No Such Page'); // How to redirect to Homepage
}
})
.factory('pagesService', ['$http', function( $http ){
var service = {};
service.fetchFromServer = function( ){
var promise = $http.jsonp('http://m.aboudcar.com/server/pages/?callback=JSON_CALLBACK')
.then( function(response ){
return response.data;
})
return promise;
};
service.fetchById = function( pageId ){
var promise = $http.jsonp('http://m.aboudcar.com/server/pages/fetchbyid/'+pageId+'?callback=JSON_CALLBACK')
.then( function(response ){
return response.data;
})
return promise;
};
return service;
}])
App.js
angular.module('GAC', ['ionic', 'GAC.controllers'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('app', {
url: "/app",
abstract: true,
templateUrl: "templates/menu.html",
controller: 'AppCtrl'
})
.state('app.cars', {
url: "/cars",
views: {
'menuContent' :{
templateUrl: "templates/cars.html",
controller: 'CarsCtrl'
}
}
})
.state('app.single', {
url: "/pages/:pageId",
views: {
'menuContent' :{
templateUrl: "templates/page.html",
controller: 'PageCtrl'
}
}
});
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/app/cars');
});
Menu.html
<ion-side-menus>
<ion-side-menu-content>
<ion-nav-bar class="bar-stable nav-title-slide-ios7">
<ion-nav-back-button class="button-clear"><i class="icon ion-ios7-arrow-back"></i> Back</ion-nav-back-button>
</ion-nav-bar>
<ion-nav-view name="menuContent" animation="slide-left-right"></ion-nav-view>
</ion-side-menu-content>
<ion-side-menu side="left">
<header class="bar bar-header bar-stable">
<h1 class="title">Menu</h1>
</header>
<ion-content class="has-header">
<ion-list>
<ion-item nav-clear menu-close ng-repeat="page in pageList" href="{{page.url}}">
{{page.name}}
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
Page.html
<ion-view title="{{page.name}}">
<ion-content class="has-header">
<h1>{{page.name}}</h1>
{{page.content}}
</ion-content>
</ion-view>

Resources