AngularJS HTML的动态lang属性属性、动态、AngularJS、HTML

2023-09-13 04:48:08 作者:掩于岁月

我需要改变HTML动态的属性一些帮助:

I need some help for change dynamically the lang attribute of HTML:

<html lang="en">

我正在与AngularJS和休息后端多语言的Web应用程序。起初我可以指定一个默认的属性,但我想它根据用户的浏览器,或者如果用户在Web应用程序中选择一些语言选项改变它来改变。

I'm making a multilanguage web application with AngularJS and rest backend. Initially I can specify a default lang attribute, but I want to change it depending on the user browser or change it if the user selects inside the web application some language option.

有一些方法来做到这一点?

There is some way to do it?

推荐答案

如果要动态更改语言。只是,你可以在一个控制器添加到HTML标记,然后更改语言。

If you want to change the language dynamically. simply you can add one controller to html tag and then change the language.

试试这个:

<html ng-app="langChange" ng-controller="langCtrl" lang={{lang}}>

</html>

JS code:

var app = angular.module(langChange,[]);
app.controller("langCtrl",[$scope,function($scope){
            $scope.lang = "en";//here you can change the language dynamically
}])