Giter VIP home page Giter VIP logo

ng-user's Introduction

@webresto/ng-user

Установка модуля

Модуль устанавливается с Git репозитория, в папку node_modules

Подключение модуля в проект

Добавьте следующие в ваш app.module.ts

import { NgUserModule } from '@webresto/ng-user';
import { ngCoreHttpInterceptorProviders } from '@webresto/ng-core';
import { ngUserHttpInterceptorProviders } from '@webresto/ng-user';
imports: [
  .......... 
  NgUserModule 
],
providers: [
  ..........
  ngCoreHttpInterceptorProviders,
  ngUserHttpInterceptorProviders
],

Использование сервиса

import { NgRestoUserService } from '@webresto/ng-user';
..........
constructor(
    private userService: NgRestoUserService
) {
    // Проверить авторизирован ли, и подписатся на изменения
    this.userService
      .userIsLoggedIn()
      .subscribe(isLoggedIn => {
        ...........
      });
    
    // Получить данные профиля и подписатся на изменения  
    this.userService
      .userProfile()
      .subscribe(user => {
        this.user = user;
        ...........
      });
      
    // Получить историю заказов
    this.userService
      .userHistory()
      .subscribe(historyItems => {
        this.historyItems = historyItems;
        ...........
      });
      
    // Прописать токен авторизации принудительно
    // Автоматически подменятся данные профиля и избранные
    this.usrtService.setAuthToken(token)
}

Директивы

[appSignIn] - Вход по логин/паролю

Пример использования в компоненте:

 <input #phone type="text">
 <input #password type="password">
 <input #rememberMe type="checkbox">
 ........
 <button appSignIn
        [phone]="phone.value"
        [password]="password.value"
        [captcha]="captcha"
        [rememberMe]="rememberMe.value"
    
        (success)="...."
        (error)="....">Войти</button>

[appSignUp] - Регистрация

Пример использования в компоненте:

 <input #name type="text">
 <input #phone type="text">
 <input #email type="text">
 <input #password type="password">
 ........
 <button appSignUp
        [name]="name.value"
        [phone]="phone.value"
        [email]="email.value"
        [password]="password.value"
        [captcha]="captcha"
    
        (success)="...."
        (error)="....">Регистрация</button>

[appAddAddress] - Добавить адрес

Пример использования в компоненте:

 <input #name type="text">
 <select #streetId ...</select>
 <input #home type="text">
 <input #housing type="text">
 ........
 <button appAddAddress
        [name]="name.value"
        [street]="streetId.value"
        [home]="home.value"
        [housing]="housing.value"
        [index]="index.value"
        [entrance]="entrance.value"
        [floor]="floor.value"
        [apartment]="apartment.value"
        [doorphone]="doorphone.value"
    
        (success)="...."
        (error)="....">Регистрация</button>

[appDeleteAddress] - Удалить адрес

Пример использования в компоненте:

 <button appDeleteAddress [address]="address">Удалить</button>

[appBalance] - добавляет значение текущего баланса

Пример использования в компоненте:

<span appBalance></span>

Директива добавит внутрь контейнера строку с текущим балансом

[appSignOut] - выход со своего аккаунта

Пример использования в компоненте:

<button appSignOut class="btn-yellow-hollow align-center">Выход</button>

[appToggleDishToFavorites] - Добавить/удалить в списке Избранных

Пример использования в компоненте:

 ........
 <button appToggleDishToFavorites
        [dish]="dish"
        
        (change)="...."
        (addedToFavorites)="...."
        (removedFromFavorites)="...."
        (error)="....">Регистрация</button>

Также в случае, если товар в избранных - добавляется автоматом класс selected. После удаления из списка избранных удаляется и класс selected.

Событие change происходит при добавлении и удалении товара в избранные со значением true/false Событие addedToFavorites - при добавлении товара в избранное Событие removedFromFavorites - при удалении из избранных

ng-user's People

Contributors

gapp0 avatar shkip avatar xziy avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.