2017-09-08 7 views
-1

私は今のユーザーのための機能モジュールを作成することを考えていると、このモジュールのようなコンポーネントがあります:角度:それに機能モジュールのメソッドを使用すると、コンポーネント

  1. 承認を。
  2. 登録;
  3. profile;
  4. 復元パスワード。私のような方法で作成したい

  1. のcreateUserを();
  2. deleteUser();
  3. updateUserProfile()。

    をUserModuleに格納し、上記のコンポーネントで使用します。

どのように私はregistrationComponentとectでUserModuleのメソッドを使用できますか? ?

+0

@AliaksandrPitkevich:どのように私はregistrationComponentと電気ショック療法でUserModuleのメソッドを使用することができます。 –

+1

多分これはhttps://scotch.io/tutorials/creating-your-first-angular-2-components –

+1

を作成するのに役立ちます。共通のtsファイルを作成し、それを他のものに継承します。コンポーネント – Sreemat

答えて

1

複数のコンポーネントでいくつかのメソッドを使用する場合は、いわゆるサービスを構築します。それは@Injectable()デコレータとtypescriptですクラスです:

import { Injectable } from '@angular/core'; 

@Injectable() 
export class UserService { 
    createUser(user) { 
    // reach out to backend via http 
    } 

    // some other functions that have to be shared and used by components 
} 

このサービスは、次のように注入することができる。

import { UserService } from 'services/user.service.ts' 

@Component({ 
    selector: 'user-create' 
}) 
export class CreateUserComponent { 
    constructor(private userService: UserService) {} 

    createUser(user) { 
    this.userService.createUser(user); // now you can call your method from the service like this 
    } 
} 
+0

を入力してください。 –

+1

角度に関する素晴らしい文書があります:https://angular.io/guide/forms –

+0

はい私は知っています、私はデータモデリングを意味します –

関連する問題