AngularJS HTML的动态lang属性 [英] AngularJS dynamic lang attribute of html

查看:363
本文介绍了AngularJS HTML的动态lang属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要改变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
}])

这篇关于AngularJS HTML的动态lang属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆