我使用的UI框架:SmartAdmin在輸入使用管道attribut
這提供了一個國際化功能與i18n
我試圖用它這個自舉驗證模塊。
如果我把這個,它的工作:
<input type="text" class="form-control" name="firstname" data-bv-notempty="true"
data-bv-notempty-message="The first name is required and cannot be empty"
data-bv-stringlength-max="50" data-bv-stringlength-message="The first name must be less than 50 characters long"/>
但是II嘗試使用管道:
<input type="text" class="form-control" name="firstname" data-bv-notempty="true"
data-bv-notempty-message="{{'The first name is required and cannot be empty' | i18n}}"
data-bv-stringlength-max="50" data-bv-stringlength-message="The first name must be less than 50 characters long" />
我得到這個錯誤:
不能結合'data-bv-notempty-message',因爲它不是'input'的已知 屬性。 (「ut type =」text「class =」form-control「 name =」firstname「data -bv-notempty =」true「 [ERROR - >] [data-bv-notempty-message] =''第一個名稱是必需的」 |國際化 「 數據BV-STRI」):NG:///UserModule/[email protected]:22
問題:在輸入attribut如何使用管道?
編輯:添加代碼管:
import { Pipe, PipeTransform } from '@angular/core';
import {I18nService} from "./i18n.service";
@Pipe({
name: 'i18n',
pure: false
})
export class I18nPipe implements PipeTransform {
constructor(public i18nService: I18nService){}
transform(phrase: any, args?: any): any {
//console.log(phrase)
return this.i18nService.getTranslation(phrase);
}
}
方法:getTranslation()
public getTranslation(phrase:string):string {
return this.data && this.data[phrase] ? this.data[phrase] : phrase;
}
結合請使用angularJs標籤。角標籤是爲角2+ :-) – alexKhymenko
@alexKhymenko它正確地被標記..它是有角度的2+問題 –
@Portekoi對不起,角2中的綁定是不同的。假設它是angular.js。 – alexKhymenko