- Hybrid Mobile Development with Ionic
- Gaurav Saini
- 248字
- 2021-07-02 23:53:49
Controllers match components
Components are the backbone of Angular and Ionic applications; you will see that almost everything is a component. You can compare controllers in Angular 1 to components in Angular 4. In controllers we used to define most of our code's logical part. We used to register the controllers with our main module. Now, in a similar way, we define our code in components in Angular 4 and if required we can export that Component class:
// Angular & Ionic 1
angular.module('wedding.controllers', [])
.controller('LoginCtrl',
function($scope, CategoryService) {
// controller function and DI of CategoryService
}
);
// Angular 4 & Ionic 32
import {Component} from '@angular/core';
import {NavController} from 'ionic-angular';
@Component({
templateUrl: 'build/pages/catalog/categories.html'
})
export class CategoryPage {
// DI of NavController for navigation
constructor(private navCtrl: NavController) {
this.nav = navCtrl;
}
}
We have dependency injection in Angular 1 as controller function arguments, while in Angular 4 we pass it inside the constructor function. Many other things such as the IIFE syntax, which we have to define in Angular 1 for keeping out controller code of the global namespace, now are not required in Angular 4 because ES 2015 modules handle name spacing for us. Also, as you can see, we have exported the CategoryPage class, we can now import it wherever this module is required.
Another major change is that $scope is replaced by the this keyword. $scope had many performance issues and already in Angular 1 developers have reduced the usage of $scope.
- OpenDaylight Cookbook
- Learning Chef
- 零基礎(chǔ)玩轉(zhuǎn)區(qū)塊鏈
- vSphere High Performance Cookbook
- 精通搜索分析
- Flask Web開發(fā)入門、進(jìn)階與實(shí)戰(zhàn)
- Kotlin Standard Library Cookbook
- 差分進(jìn)化算法及其高維多目標(biāo)優(yōu)化應(yīng)用
- 軟件項(xiàng)目管理實(shí)用教程
- 從Excel到Python:用Python輕松處理Excel數(shù)據(jù)(第2版)
- Learning ArcGIS for Desktop
- SciPy Recipes
- 交互設(shè)計(jì)師成長(zhǎng)手冊(cè):從零開始學(xué)交互
- 劍指大數(shù)據(jù):企業(yè)級(jí)電商數(shù)據(jù)倉庫項(xiàng)目實(shí)戰(zhàn)(精華版)
- 開源網(wǎng)絡(luò)地圖可視化:基于Leaflet的在線地圖開發(fā)