动态更改导航栏文本

时间:2016-08-18 02:27:36

标签: angularjs steroids appgyver supersonic

我正在为iOS和Android构建一个混合应用程序,并且有一个部分我想展示这一天。如果你在星期二打开应用程序,它会说星期二,依此类推。它是西班牙语,所以,它说“Miércoles”是星期三,但是我手动编写,我希望它改变所以如果今天是星期三,它会自动改变。

我尝试使用ng-bind和以下代码更改它:

    var today = new Date();
  if(today.getDay() == 0){
    var hoy = "Domingo";
  } else if(today.getDay() == 1){
    var hoy = "Lunes";
  }else if(today.getDay() == 2){
    var hoy = "Martes";
  }else if(today.getDay() == 3){
    var hoy = "Miercoles";
  }else if(today.getDay() == 4){
    var hoy = "Jueves";
  }else if(today.getDay() == 5){
    var hoy = "Viernes";
  }else if(today.getDay() == 6){
    var hoy = "Sábado";
  }
  $scrope.variable = hoy;

它不起作用,没有控制台错误或警告。

Image showing my app

3 个答案:

答案 0 :(得分:4)

您多次声明同一个变量,因此忽略第一个变量后的声明。

使用像这样的工作日数组会更好看:

var now = new Date();
//var weekday = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"];
var weekday = ["Domingo", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes","Sábado"];

var hoy = weekday[now.getDay()];
$scope.variable = hoy;

答案 1 :(得分:1)

看起来你有一个错字。

改变

SELECT to_char( '2014-08-08 20:48:27.097971+00'::timestamptz, 'YYYYMMDD"T"HH24MISS"Z"' ); to_char ------------------ 20140808T204827Z (1 row)

$scrope.variable = hoy;

答案 2 :(得分:1)

只需更新您的代码,

var today = new Date(),
    weekday = [ 
                "Domingo",
                "Lunes",
                "Martes",
                "Miercoles",
                "Jueves",
                "Viernes",
                "Sábado"
              ];

var hoy = weekday[today.getDay()];
$scope.variable = hoy;

演示:https://jsfiddle.net/1a148yrw/2/