2017-10-19 70 views
1

我想在客戶端和服務器端重用與Angular 4.4.5和NodeJS 7.10.1相同的一組驗證器(最新的Ubuntu回購版)。我相信這是可能的。如何在服務器端重新使用Angular進行驗證?

我的基本想法是讓NodeJS和Express上的HTTP端點工作,它接受來自角度形式的JSON數據的POST請求,創建與接收數據相同的表單並檢查它。

我的嘗試不成功,我不知道如何使用同一版本的Typescript作爲Angular用法以及如何導入帶有窗體的組件。這將是理想的看到一些簡單的例子,工作。我會盡快分享我的嘗試。

回答

0

現在我設法實例化組件這種方式。從tsconfig.json某些設置

import 'reflect-metadata'; 
import { CuComponent } from './app/cu.component'; 

console.log(new CuComponent()) 

運行tsc

創建cli.ts測試獨立創作角度分量的

tsc -t es5 --lib es2016,dom --experimentalDecorators src/cli.ts 

得到輸出:

CuComponent { 
    registration: 
    FormGroup { 
    validator: null, 
    asyncValidator: null, 
    _onCollectionChange: [Function], 
    _pristine: true, 
    _touched: false, 
    _onDisabledChange: [], 
    controls: { familyName: [Object], givenName: [Object], phone: [Object] }, 
    _valueChanges: 
     EventEmitter { 
     _isScalar: false, 
     observers: [], 
     closed: false, 
     isStopped: false, 
     hasError: false, 
     thrownError: null, 
     __isAsync: false }, 
    _statusChanges: 
     EventEmitter { 
     _isScalar: false, 
     observers: [], 
     closed: false, 
     isStopped: false, 
     hasError: false, 
     thrownError: null, 
     __isAsync: false }, 
    _status: 'VALID', 
    _value: { familyName: null, givenName: null, phone: null }, 
    _errors: null } } 

創建組件。

相關問題