Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 函数在html中以ionic格式多次运行_Javascript_Html_Angularjs_Ionic Framework - Fatal编程技术网

Javascript 函数在html中以ionic格式多次运行

Javascript 函数在html中以ionic格式多次运行,javascript,html,angularjs,ionic-framework,Javascript,Html,Angularjs,Ionic Framework,这是我的密码。在html中调用的控制器中定义的函数,但 多次安慰 在控制器中: $scope.test=function(r) { var strDateTime = r+" GMT"; var myDate = new Date(strDateTime); console.dir(myDate.toLocaleString()); return myDate.toLocaleString(); } 在HTML中,我调用如下函数: <div>{{te

这是我的密码。在html中调用的控制器中定义的函数,但 多次安慰

在控制器中:

$scope.test=function(r)
{
    var strDateTime = r+" GMT";
    var myDate = new Date(strDateTime);
    console.dir(myDate.toLocaleString());
    return myDate.toLocaleString();
}
在HTML中,我调用如下函数:

<div>{{test("2017-12-19 22:00:00")}}</div>
{{测试(“2017-12-19 22:00:00”)}

最好使用自定义过滤器(管道),因为调用示例中的scope方法会得到多次计算

角度表达式({expression}})在每个$digest循环上重新计算(有时每个循环多次)

示例如下:

const customDate=()=>{
返回(str)=>{
var strDateTime=str+“GMT”;
var myDate=新日期(strDateTime);
返回myDate.toLocalString();
}
}
var app=angular.module('app',[]).filter('customDate',customDate);
app.controller('mainController',函数($scope,$http){
$scope.datestring=“2017-12-19 22:00:00”
})

{{datestring | customDate}}

它在浏览器上正常工作,但在iphone设备上不工作。显示无效日期。新日期(“2017-12-19 22:00:00”)显示无效日期
新日期()。此外,Safari不会将该字符串识别为此处所述的有效时间格式-