Skip to content

Instantly share code, notes, and snippets.

@leuowang
leuowang / auth.guard.ts
Last active October 24, 2018 02:16
Route Guards for Ionic Apps
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Observable } from 'rxjs';
import { Router } from '@angular/router';
import * as firebase from 'firebase/app';
import 'firebase/auth';
@Injectable({
providedIn: 'root'
@leuowang
leuowang / app-routing.module.ts
Last active October 11, 2018 13:22
Firebase認證API:以Email/密碼建立會員資料
// ...
const routes: Routes = [
{ path: '', redirectTo: 'register', pathMatch: 'full' },
{ path: 'home', loadChildren: './home/home.module#HomePageModule' },
{ path: 'register', loadChildren: './register/register.module#RegisterPageModule' },
];
// ...
@leuowang
leuowang / index.js
Last active May 3, 2019 01:21
Cloud function of Firestore database trigger. It will update the document by adding an auto-incremental field.
'user strict'
const functions = require('firebase-functions');
const admin = require('firebase-admin');
// Prevent firebase from initializing twice
try {
admin.initializeApp(functions.config().firebase)
} catch (e) {}
@leuowang
leuowang / app.component.html
Last active November 6, 2017 12:51
Angular_tutorial_2way_binding
<header>
<h1> {{ site.title }} </h1>
<img src="{{ site.img_file }}">
</header>
<nav>
<ul>
<li *ngFor="let menuitem of menu">
{{ menuitem }}
</li>
</ul>
@leuowang
leuowang / app.component.html
Last active November 3, 2017 14:22
第一個Angular專案
<!--The content below is only a placeholder and can be replaced.-->
<div style="text-align:center">
<h1>
Welcome to {{title}}!
</h1>
<img width="300" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
</div>
<h2>Here are some links to help you start: </h2>
<ul>
<li>
@leuowang
leuowang / app.js
Last active August 29, 2015 14:21
Spotify preview試聽歌曲範例
angular.module('starter', ['ionic','starter.controllers', 'starter.services'])
.run(function ($ionicPlatform) {
$ionicPlatform.ready(function () {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
@leuowang
leuowang / app.js
Last active August 29, 2015 14:21
Barcode Scanner 使用Cordova Barcode Plugin(https://github.com/wildabeast/BarcodeScanner.git)與ngCordova
angular.module('starter', ['ionic', 'starter.services','starter.controllers','ngCordova'])
.controller("barCodeCtrl", function ($scope, $cordovaBarcodeScanner) {
$scope.scanBarcode = function () {
$cordovaBarcodeScanner.scan().then(function (result) {
$scope.barcode = result.text;
$scope.format = result.format;
}, function (error) {
console.warn("An error happened -> " + error);
});
};
@leuowang
leuowang / activities.html
Last active August 29, 2015 14:21
Parse User範例
<ion-view>
<ion-nav-buttons side="right">
<button class="button" ng-if="login" ng-click="logout()">登出</button>
</ion-nav-buttons>
<ion-content>
<ion-list class="list" ng-repeat="item in activities">
<ion-item class="item">
<h2>{{item.activity_name}}</h2>
<p>{{item.heldAt.iso|date:'yyyy-MM-dd HH:mm':'UTC'}},{{item.place}}</p>
<p>講師:{{item.instructor.name}}</p>
@leuowang
leuowang / app.js
Last active September 21, 2017 02:07
Google Maps API Example for Ionic Framework
var map = null;
angular.module('starter', ['ionic', 'starter.services'])
.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('list', {
url: '/list',
templateUrl: 'templates/list.html',
controller: 'listCtrl'
})
.state('detail', {
@leuowang
leuowang / app.js
Last active October 13, 2023 00:09
Facebook OAuth with ngCordovaOAuth範例
angular.module('starter', ['ionic', 'ngCordovaOauth', 'ngStorage'])
.config(function ($stateProvider, $urlRouterProvider) {
$urlRouterProvider.otherwise('/login');
$stateProvider
.state('login', {
url: '/login',
templateUrl: 'templates/login.html',
controller: 'OauthCtrl'
})
.state('feed', {