I've created a new app using the following command:
ionic start myApp sidemenu
added a home.html page to the templates folder, added the following to the app.js file:
.state('app.home', {
url: '/home',
views: {
'menuContent': {
templateUrl: 'templates/home.html',
controller: 'homeCtrl'
}
}
})
and added the following controller:
.controller('homeCtrl', function ($scope) {
ionic.Platform.ready(function () {
$scope.me = "my name";
//ionic.Platform.fullScreen(true, false);
//$cordovaStatusbar.hide();
//StatusBar.hide();
});
})
my home.html:
<ion-view>
<ion-content>
<h3 style="margin-top:30px;">User Name {{me}}</h3>
<select class="center" style="margin-top:10px;">
<option>Blue</option>
<option>Green</option>
<option>Red</option>
</select>
</ion-content>
</ion-view>
My question is how can I hide this top bar:
just from a single page\view\controller?
UPDATE
changed my controller to this:
.controller('homeCtrl', function ($scope, $ionicNavBarDelegate) {
$ionicNavBarDelegate.showBar(false);
$scope.me = "my name";
})
but still doesn't work even though the docs say it's the correct way.
Just try this,
<ion-view hide-nav-bar="true">
<ion-content>
<h3 style="margin-top:30px;">User Name {{me}}</h3>
<select class="center" style="margin-top:10px;">
<option>Blue</option>
<option>Green</option>
<option>Red</option>
</select>
</ion-content>
</ion-view>
or
add this line in your contorller
$ionicNavBarDelegate.showBar(false);
Refer
Related
I'm using angular UI Router in Ionic to build an application but my one page news.html is not loading the content.It shows the view-title but not the stuffs inside ion-content , the page is blank.
this code is inside of a template news.html
<ion-view view-title="news">
<ion-content>
<div class="list card" ng-repeat="item in articles">
<div class="item item-thumbnail-left item-text-wrap">
<h2 class="post-title">{{item.name}}</h2>
<p class="post-author">{{item.description}}</p>
</div>
</div>
</ion-content>
</ion-view>
in app.js i have added the following ui route code
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('index', {
url: '/',
templateUrl: 'templates/home.html',
controller: 'mainCtrl'
})
.state('news', {
url: '/news',
templateUrl: 'templates/news.html',
controller: 'newsCtrl'
});
$urlRouterProvider.otherwise('/');
})
and my newsCtrl is
.controller('newsCtrl',function($scope, $http){
$http.get('https://newsapi.org/v1/articles?source=the-next-web&sortBy=latest&apiKey=4ff16a30e00640cab0a2a9731ccc9510').success(function(data){
$scope.articles = data.sources;
console.log('news control');
});
Same code works
carService.controller('newsCtrl', ['$scope', '$http', function($scope, $http) {
$http.get('https://newsapi.org/v1/sources?language=en').success(function(data) {
$scope.articles = data.sources;
console.log(data);
console.log('news control');
});
}]);
DEMO
I am kind of a noob in Ionic and I need help / guidelines to build something that sounds easy.
I want to have a single page composed of multiple content, the idea is to have multiple views in the same page each of them being linked to a specific controller.
Here is my code:
index.html content:
<ion-pane>
<ion-nav-view></ion-nav-view>
<ion-view ng-controller="FirstController">
<ion-content>
</ion-content>
</ion-view>
<ion-view ng-controller="ScdController">
<ion-content>
</ion-content>
</ion-view>
</ion-pane>
In my app.js:
angular.module('app', [])
.controller('FirstController', function($scope) {
})
.controller('ScdController', function($scope) {
});
In my config.routes.js:
angular.module('app')
.config(configure);
function configure($stateProvider){
$stateProvider
.state('first', {
url: '/',
templateUrl: 'templates/first.html',
controller: 'FirstController'
})
.state('second', {
url: '/',
templateUrl: 'templates/second.html',
controller: 'ScdController'
});
}
Templates are very simple:
first.html:
<div>first</div>
second.html:
<div>Second</div>
Right now nothing is displayed.
What do you guys think?
Thanks for your help!
Your requirement is multiple named views.
Following document is useful to implement multiple views in a single page
https://github.com/angular-ui/ui-router/wiki/Multiple-Named-Views
Example code:
HTML:
<ion-view title="">
<ion-content scroll="true">
<div ui-view="first"></div>
<div ui-view="second"></div>
</ion-content>
</ion-view>
JS:
angular.module('app')
.config(function($stateProvider) {
$stateProvider
.state({
name : 'multiple-views'
views: {
'first': {
url: '/',
templateUrl: 'templates/first.html',
controller: 'FirstController'
},
'second': {
url: '/',
templateUrl: 'templates/second.html',
controller: 'ScdController'
}
}
});
Working example link: http://plnkr.co/edit/kZZ4KikwLITOxR5IGltr?p=preview
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.
I have just started to adapt the sample angular/ionic tab navigation app and have run into a problem.
When I click on a link in one view (a list of all journeys), I should be taken to a screen with details about that particular journey. (Adapted from the 'chats' in the sample app.
It doesn't quite work however. The URL changes to the expected URL but the view/page doesn't change at all. When I try to refresh the page, I am taken back to my default state/page.
The controllers are:
.controller('JourneysController', function($scope, $log, JourneyHandler) {
'use strict';
$log.debug('Activating the journey controller');
$scope.journeys = JourneyHandler.getJourneys();
})
.controller('JourneyDetailController', function($scope, $stateParams, $log) {
'use strict';
$log.debug('Activating the journey detail controller');
$scope.journey = {
journeyId: 0,
journeyStart: new Date()
};
})
The app.js defines the states as:
.state('tab.journeys', {
url: '/journeys',
views: {
'tab-journeys': {
templateUrl: 'templates/tab-journeys.html',
controller: 'JourneysController'
}
}
})
.state('tab.journey-detail', {
url: '/journey',
views: {
'tab-journey-detail': {
templateUrl: 'templates/journey-detail.html',
controller: 'JourneyDetailController'
}
}
});
$urlRouterProvider.otherwise('/tab/dash');
and the relevant templates are:
tab-journeys.html
<ion-view view-title="My Journeys">
<ion-content>
<ion-list>
<ion-item class="item-remove-animate item-avatar item-icon-right" ng-repeat="journey in journeys" type="item-text-wrap" href="#/tab/journey">
<h2>{{journey.journeyId}}</h2>
<p>{{journey.routeId}}</p>
<i class="icon ion-chevron-right icon-accessory"></i>
<ion-option-button class="button-assertive">
Delete
</ion-option-button>
</ion-item>
</ion-list>
</ion-content>
</ion-view>
and journey-detail.html
<ion-view view-title="Journey Detail">
<ion-content>
<p>This is where the journey details will go.</p>
</ion-content>
</ion-view>
There are no errors in the console so I really can't understand why it's not working.
When I encountered this same problem, I discovered that the error occurs because the controller didn't load.
Comment the controller in the state declaration and see if it works. You will need to check the controller.
I am trying to get my dashboard view from template folder when I am loading my app. I am using Ionic frame work.
My index
<body ng-app="starter">
<ion-pane>
<ion-header-bar class="bar bar-header bar-dark main-header">
<h1 class="title main-header-title"><strong>Recharge Plans</strong></h1>
</ion-header-bar>
<ion-nav-view></ion-nav-view>
</ion-pane>
My app.js
angular.module('starter', ['ionic','starter.controller','starter.service'])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('dash', {
url: '/dash',
views: {
'dash': {
templateUrl: '/templates/dash.html',
controller: 'DashCtrl'
}
}
});
$urlRouterProvider.otherwise('/dash');
});
My controller.js
angular.module('starter.controller',[])
.controller('DashCtrl', function($scope) {
alert("ok");
})
In 'www\templates' I have a file named dash.html.
My dash.html is
<ion-view ng-controller="DashCtrl">
<ion-content>
<div class="list searc-panel">
<label class="item item-input item-select">
<div class="input-label">
Select Operator
</div>
<select>
<option>Select</option>
<option>Airtel</option>
<option>Vodafone</option>
</select>
</label>
<label class="item item-input item-select">
<div class="input-label">
Select State
</div>
<select>
<option>Select</option>
<option>West bengal</option>
<option>Kolkata</option>
</select>
</label>
<button class="button button-full button-positive">
Search My Plans
</button>
</div>
</ion-content>
</ion-view>
But when i hit 'file:///C:/Users/Sanjeev/RechargePlans/www/index.html' in browser then it renders me to 'file:///C:/Users/Sanjeev/RechargePlans/www/index.html#/dash' with a blank view .
What I miss??
If you are going to name your views with Ionic then your ion-view tab HTML needs to look like this:
<ion-nav-view name="you-view-name"></ion-nav-view>
Usually with Ionic apps you have a root state and everything stems off that, so:
app.js file:
angular.module('starter', ['ionic','starter.controller','starter.service'])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('root', {
url: '/',
templateUrl: '/templates/tabs.html',
controller: 'rootCtrl'
}
});
.state('root.dash', {
url: '/dash',
views: {
'dash': {
templateUrl: '/templates/dash.html',
controller: 'DashCtrl'
}
}
});
$urlRouterProvider.otherwise('/dash');
});
index.html:
<ion-nav-view></ion-nav-view>
tabs.html:
<ion-nav-view name="dash"></ion-nav-view>
In any case, if you are naming your views them your ion-view HTML tag needs to have a name attribute with the name of the view in it.
Hope this helps
you should not run ionic app by "file:///C:/Users/Sanjeev/RechargePlans/www/index.html". you should be using ionic cli tool to run your ionic project. Go to cmd > navigate to your project folder and than run ionic serve and you will be able to see output.