我添加HttpInterceptor后ngx-translate无法正常工作

时间:2018-07-26 10:49:36

标签: angular6 angular-http-interceptors angular-pipe angular-i18n

就像标题中所说的那样,一切正常,直到我将HttpInterceptor添加到我的代码中为止,问题是我有两种方法可以转换字段,一种仍然可以正常工作,而第二种却不像下面所示

 <dx-button 
    (click)="logIn()" 
    type="default" id="buttonLogIn"
    text="{{ 'LoginPage.Login'|translate }}">
</dx-button>
<span id="containerStayConnected"><input type="checkbox" id="stayConnected" [(ngModel)]="stayConnected" /><label for="stayConnected" translate>LoginPage.StayConnected</label></span>
<a id="forgetPassword" translate (click)="isPopupForgotPasswordVisible = !isPopupForgotPasswordVisible">LoginPage.ForgotPassword</a><br><br><br>

在balise内的翻译有效,而在dxButton中使用管道的翻译无效 这是我的拦截器服务

@Injectable()
export class AuthInterceptorService implements HttpInterceptor {

constructor(public auth: AuthService) {}

intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    const userId = localStorage.getItem('access_token');
    request = request.clone({
        setHeaders: {
            Authorization: `Bearer ${userId}`
        }
    });
    return next.handle(request);
}

} 有谁知道为什么我添加httpInterceptor后使用Pipe停止工作的翻译?

1 个答案:

答案 0 :(得分:0)

我通过从构造函数中删除var mysql = require('mysql2/promise'); async function main () { var conn = await mysql.createConnection({ host : CONFIG.db_host, user : CONFIG.db_user, password : CONFIG.db_password, database : CONFIG.db_name }); var [rows] = await conn.query('SELECT * FROM table WHERE col=?', col); var out = []; for (var row of rows) { var result = await db.query('SELECT * FROM other_table WHERE col=?', row.col); out.push(result); } // all queries are done } main(); 来解决了这个问题。 我认为造成问题的是HttpInterceptor和AuthService都注入HttpClient。 如果有人有兴趣检查有关类似问题的更多信息,请在此处检查 https://github.com/angular/angular/issues/18224