Your system information:
Cordova CLI: 6.0.0
Ionic Version: 1.2.4
Ionic CLI Version: 1.7.14
Ionic App Lib Version: 0.7.0
OS:
Node Version: v5.5.0
<ion-view view-title="Change Header" class="bar-assertive">
<ion-content>
<ion-list>
<ion-radio ng-model="color" ng-value="'bar-stable'">Stable</ion-radio>
<ion-radio ng-model="color" ng-value="'bar-assertive'">Assertive</ion-radio>
<ion-radio ng-model="color" ng-value="'bar-calm'">Calm</ion-radio>
</ion-list>
<span ng-bind="color"></span>
</ion-content>
</ion-view>
As you can see the code above, I add class="bar-assertive" to ion-view tags, and the navbar should change color to red, but the result remain the same with previous. There's no change in background-color of the navbar
You can set the nav-bar-color in your index with this code:
<ion-nav-bar class="bar-assertive"></ion-nav-bar>
<ion-nav-view></ion-nav-view>
If you need to customize nav-bar (i.e. apply a specific class) add an <ion-nav-bar> tag inside the <ion-view> you want with a custom nav bar:
<ion-nav-bar align-title="right" class="bar-positive">...</ion-nav-bar>
Here is an example: http://codepen.io/beaver71/pen/XXeydY
But if you want to set different color for each tabs/view you could also use ngClass and $stateChangeSuccess:
<ion-nav-bar ng-class="headerClass"></ion-nav-bar>
<ion-nav-view></ion-nav-view>
In your app (in run section) you have to set $scope.headerClass according to the current state:
.run(function($state, $rootScope) {
$rootScope.$on('$stateChangeSuccess', function (evt, toState) {
if (toState.name == "xyz") {
$rootScope.headerClass = 'bar-positive';
} else {
$rootScope.headerClass = 'bar-assertive';
}
});
})
Related
I created scrollTo functionality by clicking on an icon in a sidebar.
The scrolling works but the ion-header is moved out of view when scrolling to the desired location.
Here is a video of the behavior I am describing:
https://drive.google.com/file/d/1XeCr0RKOlas_9PpZZTUx5pEteA8Np42-/view?usp=sharing
Almost identical template works with Ionic 4 & Angular
Any ideas on what is wrong here?
Template
<template>
<ion-modal>
<ion-header>
<ion-toolbar>
// Close modal button
</ion-toolbar>
<ion-searchbar />
<div>
// Vertical column of scroll to anchor tags
<a #click="scrollTo('Math')">
<ion-icon :icon="calculator"/>
</a>
</div>
</ion-header>
<ion-content>
<ion-list>
<ion-list-header id="Math">
<ion-label>
Math
</ion-label>
</ion-list-header>
</ion-list>
</ion-content>
</ion-modal>
</template>
scrollTo Function
function scrollTo (category: string) {
let elementId = category.replace(' ', '')
let subject = document.getElementById(elementId)
if (subject) {
subject.scrollIntoView({ behavior: 'smooth', block: 'start' })
}
}
I built an ionic5 application that utilizes a loop to add ion-slides whose content are different radio groups whose contents are pulled from an array. My problem is when I try to use slideNext or slideTo to switch slides, it fails to work. I can only get it to work after refreshing the browser and doesnt work at all when I build an android app and test.
The code I am trying is:
<ion-slides #quizSlider>
<ion-slide *ngFor="let question of questions;let i = index">
<ion-list lines="none">
<ion-radio-group [(ngModel)]="singleanswer">
<ion-item *ngFor="let answer of question.answers">
<ion-label>{{answer}}</ion-label>
<ion-radio slot="start" value="{{answer}}">
</ion-radio>
</ion-item>
</ion-radio-group>
<div fxLayout="row" fxLayoutAlign="center" >
<ion-button color="primary" (click)="checkUserAnswers(i)">Check</ion-button>
</div>
</ion-list>
</ion-slide>
</ion-slides>
And .ts code:
import { IonSlides } from '#ionic/angular';
#ViewChild('quizSlider') quizSlider: IonSlides;
export class Quiz {
questions: Question[];
constructor() {}
checkUserAnswers(questionNo)
{
if(this.questions.length == questionNo + 1)
{
this.router.navigate(['complete']);
}
else
{
console.log('test');
//this.quizSlider.slideNext();
//this.quizSlider.lockSwipes(false);
this.quizSlider.slideNext();
//this.quizSlider.lockSwipes(true);
//let currentIndex = this.quizSlider.getActiveIndex().then( (val) => console.log(val) );
//console.log('Current Slide: ' + currentIndex);
//this.quizSlider.slideTo(questionNo + 1);
}
}
}
Not sure if its related but the ionic environment I am using is:
Ionic CLI : 6.11.8
Ionic Framework : #ionic/angular 5.0.5
#angular-devkit/build-angular : 0.900.7
#angular-devkit/schematics : 9.0.7
#angular/cli : 9.0.7
#ionic/angular-toolkit : 2.2.0
UPDATE
I have attempted using swipe and I realized that (like the case of using button event) the slide change only works after the page is refreshed. I have tried downgrading to ionic4 but the problem has persisted
I'm building a mobile app in ionic and I wanna make a slack-like side menu by placing slides.
For example, when you click on main menu item, it will slide out another slide in the sidemenu as slack does.
I tried to use ion-slides in ion-menu but slides is not working.
Check out the screenshot, please.
Here is the code snippet.
<ion-menu [content]="mycontent" [swipeEnabled]="false">
<ion-content>
<ion-slides>
<ion-slide>
<h1>Slide 1</h1>
</ion-slide>
<ion-slide>
<h1>Slide 2</h1>
</ion-slide>
<ion-slide>
<h1>Slide 3</h1>
</ion-slide>
</ion-slides>
</ion-content>
</ion-menu>
<ion-nav #mycontent [root]="rootPage"></ion-nav>
Here is what I'm trying to build.
Any thoughts on how to implement this?
Thanks.
The ion-slides component makes use of the Swiper library under the hood. Part of the init code for Swiper depends on knowing the width of the slide container, and the code uses clientWidth to get it. Since the menu starts out with display:none, the retrieved width is always zero and the init code bails on you.
You can get around this by temporarily setting display:block while Swiper initializes. I have my side menu inside of a component, so you may need to adjust this code to your situation:
app.html:
<sidebar [content]="content"></sidebar>
<ion-nav #content [root]="rootPage" swipeBackEnabled="false"></ion-nav>
sidebar.html:
<ion-menu [content]="content" swipeEnabled="false">
<ion-content>
<ion-slides pager>
<ion-slide>
<h2>Slide 1</h2>
</ion-slide>
<ion-slide>
<h2>Slide 2</h2>
</ion-slide>
<ion-slide>
<h2>Slide 3</h2>
</ion-slide>
</ion-slides>
</ion-content>
</ion-menu>
sidebar.component.ts:
...
#Component({
selector: 'sidebar',
templateUrl: 'sidebar.html',
})
export class SidebarComponent implements AfterViewInit {
#Input('content') content: NavController;
#ViewChild(Slides) slides: Slides;
#ViewChild(Menu, { read: ElementRef }) menuRef: ElementRef;
// Use Renderer2 instead of direct DOM manipulation through the
// ElementRef.nativeElement.
//
// #see: https://medium.com/#kmathy/angular-manipulate-properly-the-dom-with-renderer-16a756508cba
//
constructor(private renderer: Renderer2) {
}
// ViewChild template references might not be available until
// AfterViewInit lifecycle hook runs.
//
// #see: https://blog.angular-university.io/angular-viewchild/
//
ngAfterViewInit() {
this.renderer.setStyle(this.menuRef.nativeElement, 'display', 'block');
setTimeout(() => {
// Swiper init has its own ngAfterViewInit code that delays 300ms
// before running. Don't remove the 'display' style until after that.
this.renderer.removeStyle(this.menuRef.nativeElement, 'display');
}, 310);
}
}
https://i.stack.imgur.com/NnhMY.png
https://i.stack.imgur.com/NIYZm.png
I took this from a site and I'm trying to have one like this only on the right side of my page. In my page i have a header,footer and in the content area i have this ion slide box where the images will be sliding one after the other. so i want a right carousel like in the second image link..
According to the Ionic Docs you can. The ion-slide-boxelement comes with the $ionicSlideBoxDelegate service that provides helper methods to control the slides.One of these helper functions on the service is next(). this allows you to go to next slide on a button click event.All you need to do is position your button as required and use the code as below(slightly modified from documentation).
USAGE:
//Your view
<ion-view>
<ion-slide-box>
<ion-slide>
<div class="box blue">
Slide 1
</div>
</ion-slide>
<ion-slide>
<div class="box red">
Slide 2!
</div>
</ion-slide>
</ion-slide-box>
//Your button
<button ng-click="nextSlide()" class = "button-icon ion-chevron-right"></button>
</ion-view>
//In your controller
function MyCtrl($scope, $ionicSlideBoxDelegate) {
$scope.nextSlide = function() {
$ionicSlideBoxDelegate.next();
}
}
<ion-header-bar>
Showing at {{distance.current_scroll_distance}}
</ion-header-bar>
<ion-list>
<ion-item collection-repeat='results in data.results'>
{{result.name}} / {{result.distance}}
</ion-item>
</ion-list>
I need to detect scroll on the ion list, and then determine which is the first visible ion-item, to update current_scroll_distance on headbar.
help will be appreciated.
I do not understand referred to "Which is the first visible ion-item"?
Remember that each ng-repeat there is a $ index! and that is as a counter of the elements, if you want to identify the first, just to see $ index == 0?
You need to call an event, whichever you need, and then capture the $index for example using ng-click:
<ion-header-bar>
Showing at {{distance.current_scroll_distance}}
</ion-header-bar>
<ion-list>
<ion-item collection-repeat='results in data.results'>
<div ng-click="captureElemnt($index)">{{result.name}} / {{result.distance}}</div>
</ion-item>
</ion-list>
js:
$scope.captureElement = function(index){
if (index == 0){
//do whatever you need
}
}