- Détails
- Écrit par : Richard GAUTHIER
- Clics : 1378
"},{"radio":[{"label":"1999","sol":true},{"label":"1979"},{"label":"2019","sol":false},{"label":"1959","sol":false}]}],[{"text":"En quelle année a été créé Google Earth?"},{"radio":[{"label":"2005","sol":true},{"label":"2015","sol":false},{"label":"1965","sol":false},{"label":"1935","sol":false}]}],[{"text":"En quelle année a été créé Street View?"},{"radio":[{"label":"2009","sol":true},{"label":"2015","sol":false},{"label":"1965","sol":false},{"label":"1935","sol":false}]}],[{"text":"Combien de satellites faut-il au minimum pour qu'un récepteur GPS fonctionne?"},{"radio":[{"label":"4","sol":true},{"label":"1","sol":false},{"label":"6","sol":false},{"label":"10","sol":false}]}],[{"text":"
"},{"radio":[{"label":"C'est une horloge atomique.","sol":true},{"label":"C'est une horloge à quartz."},{"label":"C'est une horloge à ressort.","sol":false},{"label":"C'est une horloge astronomique.","sol":false}]}],[{"text":"Quelle est la précision des horloges dans les gps?"},{"radio":[{"label":"100 nanosecondes","sol":true},{"label":"100 microsecondes","sol":false},{"label":"1 seconde","sol":false},{"label":"1 milliseconde","sol":false}]}],[{"text":"A qui appartient le système de localisation Galiléo?"},{"radio":[{"label":"A l'Europe","sol":true},{"label":"Aux Etats-Unis","sol":false},{"label":"A la Russie","sol":false},{"label":"A la Chine","sol":false}]}],[{"text":"Quelle est la vitesse de la lumière dans le vide?"},{"radio":[{"label":"300 000 000 m/s","sol":true},{"label":"300 m/s","sol":false},{"label":"300 000 m/s","sol":false},{"label":"300 000 000 000 m/s","sol":false}]}],[{"text":"Quelle est la formule pour calculer une vitesse v?"},{"radio":[{"label":"v = d * t
- Détails
- Écrit par : Richard GAUTHIER
- Clics : 1461
https://docs.google.com/presentation/d/1ImCWqUaGzUmkwtGiseBXdICXTjDrB-yTXvnqRRexD3U/edit?usp=sharing
- Détails
- Écrit par : Richard GAUTHIER
- Clics : 1146
J'ai compris
nous utilisons les cookies afin de personnaliser le contenu et les publicités, de fournir des fonctionnalités pour les réseaux sociaux et analyser notre traffic. Nous partageons également des informations sur votre usage de notre site avec nos réseaux sociaux, publicitaires et partenaires d'analyse Voir les détails
djamware fullstack programming tutorial
Programming Blog
Hire me
Resources
Home > Programming Blog > Ionic Framework
Ionic 3 and Angular 4 Multi Level Accordion Menu Example
by Didin J., updated on août 27, 2019
Ionic 3 and Angular 4 Multi Level Accordion Menu Example
An example of multi level accordion menu with dynamic data using latest Ionic 3 and Angular 4.
This is an example of a multi-level accordion menu with dynamic data using latest Ionic 3 and Angular 4. Previously we have created the simple hardcoded accordion list using Ionic 2 and Angular 2 in this tutorial.
Table of Contents:
Create New Ionic 3 and Angular 4 Side Menu App
Create Nested Array of Objects
Create and Call Service/Provider for Accessing Data
Create Multilevel Accordion Menu
Another name of Accordion is the collapsible list. The accordion is a graphical control element comprising a vertically stacked list of items, such as labels or thumbnails. Each item can be "expanded" or "collapsed" to reveal the content associated with that item. There can be zero expanded items, exactly one, or more than one item expanded at a time, depending on the configuration.
Create New Ionic 3 and Angular 4 Side Menu App
We will start this tutorial by creating new Ionic 3 and Angular 4 app. This time we will use generated side menu app. Open and edit the terminal or Node.js command line then type this command.
ionic start ionic3-accordion-menu sidemenu --v2
Or if you are using the latest Ionic CLI, type this command.
ionic start ionic3-accordion-menu sidemenu --type ionic-angular
That command will create new Ionic 3 app with the name 'ionic3-accordion-menu' using default template 'sidemenu'. Go to the newly created app folder.
cd ionic3-accordion-menu
Run the Ionic 3 app on the browser.
ionic serve -l
You should see this side menu.
Ionic 3 and Angular 4 Multi Level Accordion Menu Example - Side Menu
Right now, we will skip lazy loading pages configuration because we will focus only on the multilevel accordion menu. You can find more about lazy loading and Ionic 3 getting started here.
Create Nested Array of Objects
We have to create nested Array of objects which it's contains multilevel arrays. Create a new folder and JSON file in the asset folder.
mkdir src/assets/data
touch src/assets/data/menus.json
Open and edit 'menus.json' then add this lines of data.
[
{
"category":"PC",
"subs": [
{
"subcategory":"Processor",
"manufactures": [
{
"manufacture":"Intel"
},
{
"manufacture":"AMD"
}
]
},
{
"subcategory":"Motherboard",
"manufactures": [
{
"manufacture":"Asus"
},
{
"manufacture":"AMD"
},
{
"manufacture":"GigaByte"
},
{
"manufacture":"Intel"
}
]
},
{
"subcategory":"Memory",
"manufactures": [
{
"manufacture":"Visipro"
},
{
"manufacture":"Crucial"
},
{
"manufacture":"VenomRX"
}
]
}
]
},
{
"category":"Laptop",
"subs": [
{
"subcategory":"Notebook",
"manufactures": [
{
"manufacture":"Lenovo"
},
{
"manufacture":"Dell"
}
]
},
{
"subcategory":"Netbook",
"manufactures": [
{
"manufacture":"Lenovo"
},
{
"manufacture":"Dell"
},
{
"manufacture":"Acer"
},
{
"manufacture":"HP"
}
]
}
]
},
{
"category":"Printer",
"subs": [
{
"subcategory":"Laserjet",
"manufactures": [
{
"manufacture":"HP"
},
{
"manufacture":"Brother"
},
{
"manufacture":"Canon"
},
{
"manufacture":"Samsung"
}
]
},
{
"subcategory":"Deskjet",
"manufactures": [
{
"manufacture":"HP"
},
{
"manufacture":"Canon"
},
{
"manufacture":"Epson"
}
]
}
]
}
]
Create and Call Service/Provider for Accessing Data
To access JSON data we have to create new service or provider to keep app modular. Type this command to create it.
ionic g provider DataService
Open and edit 'src/providers/data-service.ts' add 'Response' to 'Http' import.
import { Http, Response } from "@angular/http";
Create this function for call JSON data.
getMenus(){
return this.http.get('assets/data/menus.json')
.map((response:Response)=>response.json());
}
Register this service in 'app.module.ts' by open and edit 'src/app/app.module.ts' then add this import.
import { HttpModule } from '@angular/http';
import { DataService } from '../providers/data-service';
Add 'HttpModule' in '@NgModule' imports.
...
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
],
...
Add 'DataService' in '@NgModule' providers.
...
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
DataService
]
...
Because menu holds by component, we have to edit it to call data for the menu from service/provider. Open and edit 'src/app/app.component.ts' then add this import.
import { DataService } from '../providers/data-service';
Replace this line.
pages: Array<{title: string, component: any}>;
With this.
pages: any;
Now, inject 'DataService' in constructor parameter and add this function for calling JSON data inside of the constructor.
constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen, public dataService: DataService) {
this.initializeApp();
this.dataService.getMenus()
.subscribe((response)=> {
this.pages = response;
console.log(this.pages);
});
}
Create Multilevel Accordion Menu
Now, is the point. Creating multilevel Accordion Menu with Ionic 3 and Angular 4. Open and edit 'src/app/app.html' the add this lines of codes inside '<ion-content>'.
<ion-content>
<ion-list>
<ion-item *ngFor="let p of pages" text-wrap>
{{p.category}}
<ion-list>
<ion-item *ngFor="let s of p.subs" text-wrap>
{{s.subcategory}}
<ion-list>
<ion-item *ngFor="let m of s.manufactures" text-wrap>
{{m.manufacture}}
</ion-item>
</ion-list>
</ion-item>
</ion-list>
</ion-item>
</ion-list>
</ion-content>
After we re-run the Ionic 3 app, the menu should look like this.
Ionic 3 and Angular 4 Multi Level Accordion Menu Example - Multi Level Menu
As you can see, there is 3 level of the menu. For that, we have to make accordion to hide child menus. Open and edit 'src/app/app.component.ts' then declare this variable.
showLevel1 = null;
showLevel2 = null;
Create new functions for toggle show/hide level 2 and level 3 of the menu.
toggleLevel1(idx) {
if (this.isLevel1Shown(idx)) {
this.showLevel1 = null;
} else {
this.showLevel1 = idx;
}
};
toggleLevel2(idx) {
if (this.isLevel2Shown(idx)) {
this.showLevel1 = null;
this.showLevel2 = null;
} else {
this.showLevel1 = idx;
this.showLevel2 = idx;
}
};
Also, create the function for check if level 2 and 3 is shown or hidden.
isLevel1Shown(idx) {
return this.showLevel1 === idx;
};
isLevel2Shown(idx) {
return this.showLevel2 === idx;
};
Now, open and edit 'src/app/app.html' then replace all list with this list.
<ion-content>
<ion-list>
<ion-item *ngFor="let p of pages; let i=index" text-wrap (click)="toggleLevel1('idx'+i)" [ngClass]="{active: isLevel1Shown('idx'+i)}">
<h4>
{{p.category}}
<ion-icon color="success" item-right [name]="isLevel1Shown('idx'+i) ? 'arrow-dropdown' : 'arrow-dropright'"></ion-icon>
</h4>
<ion-list *ngIf="isLevel1Shown('idx'+i)">
<ion-item *ngFor="let s of p.subs; let i2=index" text-wrap (click)="toggleLevel2('idx'+i+'idx'+i2)" [ngClass]="{active: isLevel2Shown('idx'+i+'idx'+i2)}">
<h4>
{{s.subcategory}}
<ion-icon color="success" item-right [name]="isLevel2Shown('idx'+i+'idx'+i2) ? 'arrow-dropdown' : 'arrow-dropright'"></ion-icon>
</h4>
<ion-list *ngIf="isLevel2Shown('idx'+i+'idx'+i2)">
<ion-item *ngFor="let m of s.manufactures" text-wrap>
{{m.manufacture}}
</ion-item>
</ion-list>
</ion-item>
</ion-list>
</ion-item>
</ion-list>
</ion-content>
Then re-run the Ionic 3 app and see the results in the browser.
Ionic 3 and Angular 4 Multi Level Accordion Menu Example - Multi Level Accordion Menu
That it's for now, we are leaving this tutorial without action for click on each menu item. We know this isn't a best and simple way for creating multiple accordions. For that, we need suggestions and best algorithm to make this tutorial better and useful for everyone.
You can find the source code on our GitHub.
We know that building beautifully designed Ionic apps from scratch can be frustrating and very time-consuming. Check Ionic 4 - Full Starter App and save development and design time. Android, iOS, and PWA, 100+ Screens and Components, the most complete and advance Ionic Template.
That just the basic. If you need more deep learning about Ionic, Angular, and Typescript, you can take the following cheap course:
IONIC 4 Design Hybrid Mobile Applications IOS & Android
Wordpress Rest API and Ionic 4 (Angular) App With Auth
Mobile App from Development to Deployment - IONIC 4
Ionic 4 Crash Course with Heartstone API & Angular
Ionic 4 Mega Course: Build 10 Real World Apps
Thanks.
Follow
Ezoicreport this ad
Previous Article
Step by Step Tutorial of Ionic 3, Angular 4 and Google Maps Directions Service
Next Article
Ionic 3 Google Plus Authentication Tutorial
Related Articles
Ionic 5 Tutorial: OAuth2 Login Example (Vue)
Ionic 5 Tutorial: Create Offline Price Checker (Angular 9)
Build Ionic 5 React Firebase Coronavirus Dashboard Mobile App
Ionic 5 Tutorial: Create Ionic Calculator App (Angular)
Upgrade the existing Ionic 4 app to Ionic 5 and Add New Feature
Ionic 4 Tutorial: How to Create Mobile Apps Quickly
Ionic 4 Tutorial: Ionic Responsive Grid Angular 8 Examples
Ionic 4 Tutorial: Facebook Login Example
Ionic 4 Tutorial: Angular 8 Multilevel Accordion Menu Example
Ionic 4 and Angular 8: Radio Button and Checkbox in FormArray
Build Android/iOS Mobile Apps using Ionic 4 React.js Capacitor
Ionic 4 Angular 8 Tutorial: Learn to Build CRUD Mobile Apps
Ionic 4 and Angular 7 Tutorial: Securing Pages using Route Guard
Ionic 4, Angular 7 and Cordova Crop and Upload Image
Push Notification using Ionic 4 and Firebase Cloud Messaging
Ionic 4 and Angular 7 Tutorial: HTTP Interceptor Example
Ionic 4, Angular 7 and Cordova Tutorial: Build CRUD Mobile Apps
Ionic 4, Angular 6 and Cordova: Export and View PDF File
Ionic 4 Angular 6 Tutorial: Call Multiple Services at Once
Ionic 4 and Angular 6 Tutorial: Firebase Realtime CRUD Mobile App
Programming Blog
React Native
HTML 5 Tutorial
ASP.NET Core
React.js
Vue.js
Angular
Java
Node.js
CSS 3
Javascript
Ionic Framework
MongoDB
Groovy and Grails
Flutter Tutorial
All Articles
Popular Articles:
Angular 8 Tutorial: REST API and HttpClient Examples (6366)
Angular Material Form Controls Select (mat-select) Example (4559)
Angular 8 Tutorial: Routing & Navigation Example (3726)
Angular 8 Tutorial: Observable and RXJS Examples (2920)
Flutter Tutorial: Firebase Cloud Messaging FCM Push Notification (2501)
Angular Material Form Controls, Form Field and Input Examples (2488)
Angular HttpClient (6/7/8/9/10): Consume REST API Example (2424)
Angular 10 Universal Server Side Rendering (SSR) CRUD Example (2333)
React.js Tutorial: Facebook Login Example (2045)
Push Notification using Ionic 4 and Firebase Cloud Messaging (1958)
Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly (1757)
React Native Tutorial: SQLite Offline Android/iOS Mobile App (1737)
Angular 8 Tutorial: Facebook Login (1327)
Angular 9 Tutorial: Creating Firebase Chat Web App (1313)
Ionic 4, Angular 6 and Cordova: Export and View PDF File (1248)
Ezoicreport this ad
©2012-2018 Djamware.com | Privacy Policy | About Us | Contact Us | RSS
Share to Facebook
, Number of shares
Share to Twitter
Share to Pinterest
, Number of shares13
Share to LinkedIn
Share to Reddit
, Number of shares
More AddThis Share options
, Number of shares
29
SHARES
SHARES
- Détails
- Écrit par : Richard GAUTHIER
- Clics : 3402
EXERCICE 1
On a relevé les valeurs moyennes annuelles des températures à Paris pour la période allant de 2013 à 2019. Les résultats ont été récupérés sous la forme de deux listes : l’une pour les températures, l’autre pour les années :
t_moy = [14.9, 13.3, 13.1, 12.5, 13.0, 13.6, 13.7] annees = [2013, 2014, 2015, 2016, 2017, 2018, 2019]
Écrire la fonction mini qui prend en paramètres le tableau releve des relevés et le tableau date des dates et qui renvoie la plus petite valeur relevée au cours de la période et l’année correspondante.
Exemple :
>>> mini(t_moy, annees) 12.5, 2016
EXERCICE 2
Écrire une fonction python appelée nb_repetitions qui prend en paramètres un élément elt et une liste tab et renvoie le nombre de fois où l’élément apparaît dans la liste.
Exemples :
>>> nb_repetitions(5,[2,5,3,5,6,9,5])
3
>>> nb_repetitions('A',[ 'B', 'A', 'B', 'A', 'R']) 2
>>> nb_repetitions(12,[1, '! ',7,21,36,44])
0
EXERCICE 3
Un mot palindrome peut se lire de la même façon de gauche à droite ou de droite à gauche : bob, radar, et non sont des mots palindromes.
De même certains nombres sont eux aussi des palindromes : 33, 121, 345543.
L’objectif de cet exercice est d’obtenir un programme Python permettant de tester si un
nombre est un nombre palindrome.
Pour remplir cette tâche, on vous demande de compléter le code des trois fonctions ci- dessous sachant que la fonction est_nbre_palindrome s’appuiera sur la fonction est_palindrome qui elle-même s’appuiera sur la fonction inverse_chaine.
La fonction inverse_chaine inverse l'ordre des caractères d'une chaîne de caractères chaine et renvoie la chaîne inversée.
La fonction est_palindrome teste si une chaine de caractères chaine est un palindrome. Elle renvoie True si c’est le cas et False sinon. Cette fonction s’appuie sur la fonction précédente.
La fonction est_nbre_palindrome teste si un nombre nbre est un palindrome. Elle renvoie True si c’est le cas et False sinon. Cette fonction s’appuie sur la fonction précédente.
Compléter le code des trois fonctions ci-dessous.
def inverse_chaine(chaine): result = ...
for caractere in chaine: result = ...
return result
def est_palindrome(chaine): inverse = inverse_chaine(chaine) return ...
def est_nbre_palindrome(nbre): chaine = ...
return est_palindrome(chaine)
Exemples :
>>> inverse_chaine('bac') 'cab' >>> est_palindrome('NSI') False
>>> est_palindrome('ISN-NSI') True >>>est_nbre_palindrome(214312) False >>>est_nbre_palindrome(213312) True
EXERCICE 4:
La fonction rendu_monnaie_centimes prend en paramètres deux nombres entiers positifs s_due et s_versee et elle permet de procéder au rendu de monnaie de la différence s_versee – s_due pour des achats effectués avec le système de pièces de la zone Euro. On utilise pour cela un algorithme qui commence par rendre le maximum de pièces de plus grandes valeurs et ainsi de suite. La fonction renvoie la liste des pièces qui composent le rendu.
Toutes les sommes sont exprimées en centimes d’euros. Les valeurs possibles pour les pièces sont donc [1, 2, 5, 10, 20, 50, 100, 200].
Ainsi, l’instruction rendu_monnaie_centimes(452, 500) renverra la liste [20, 20, 5, 2, 1].
En effet, la somme à rendre est de 48 centimes soit 20 + 20 + 5 + 2 + 1.
Le code de la fonction est donné ci-dessous :
def rendu_monnaie_centimes(s_due, s_versee): pieces = [1, 2, 5, 10, 20, 50, 100, 200] rendu = ... a_rendre = ...
i = len(pieces) - 1 while a_rendre > ... :
if pieces[i] <= a_rendre : rendu.append(...) a_rendre = ...
else :
i = ...
return rendu
Compléter ce code pour qu’il donne :
>>> rendu_monnaie_centimes(700,700) [] >>> rendu_monnaie_centimes(112,500) [200, 100, 50, 20, 10, 5, 2, 1]
- Détails
- Écrit par : Richard GAUTHIER
- Clics : 2018