Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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
Angularjs 变量值不会在运行时替换为角js_Angularjs_Angularjs Scope - Fatal编程技术网

Angularjs 变量值不会在运行时替换为角js

Angularjs 变量值不会在运行时替换为角js,angularjs,angularjs-scope,Angularjs,Angularjs Scope,我是AngularJs的新手。这是我的密码。在本文中,我试图通过获取系统日期来构建url。但是在jsonp请求时,这些值不会被替换。我不知道为什么 在这里,我尝试手动添加参数。我得到了价值观。但是当我尝试使用变量时,我没有得到输出 $scope.getCurrentMonthData = function(){ $scope.date = new Date(); $scope.startday = 1; $scope.currentday

我是AngularJs的新手。这是我的密码。在本文中,我试图通过获取系统日期来构建url。但是在jsonp请求时,这些值不会被替换。我不知道为什么

在这里,我尝试手动添加参数。我得到了价值观。但是当我尝试使用变量时,我没有得到输出

    $scope.getCurrentMonthData = function(){

        $scope.date = new Date();
        $scope.startday = 1;
        $scope.currentday = $scope.date.getDate()+1;
        $scope.month = $scope.date.getMonth()+1;
        $scope.year = $scope.date.getFullYear();
        $scope.start= $scope.year+'/'+$scope.month+'/'+$scope.startday;

        $scope.end = $scope.year+'/'+$scope.month+'/'+$scope.currentday;

        $scope.url1 = $rootScope.ApiWeatherHost+'/climo/v1/actuals/'+$scope.location_key+'.json?start='+$scope.start+'&end='+$scope.end+'&apikey='+$rootScope.ApiKey;

        $scope.url2 = $rootScope.ApiWeatherHost+'/climo/v1/records/'+$scope.location_key+'.json?start='+$scope.start+'&end='+$scope.end+'&apikey='+$rootScope.ApiKey;

        $scope.url3 = $rootScope.ApiWeatherHost+'/climo/v1/normals/'+$scope.location_key+'.json?start='+$scope.start+'&end='+$scope.end+'&apikey='+$rootScope.ApiKey;

        $http.jsonp($scope.url1).then(function(msg){
          console.log(msg.data);
        });
       $http.jsonp($scope.url2).then(function(msg){
          console.log(msg.data);
        });
        $http.jsonp($scope.url3).then(function(msg){
          console.log(msg.data);
        });

  };

我看不到您在哪里定义
location\u key
,因此我不确定这是否是您的问题,但当我运行以下代码时,我看到所有三个URL都已创建

您是否检查了尝试发出这些请求时是否有错误

(函数($scope,$rootScope){
$scope.date=新日期();
$scope.startday=1;
$scope.currentday=$scope.date.getDate()+1;
$scope.month=$scope.date.getMonth()+1;
$scope.year=$scope.date.getFullYear();
$scope.start=$scope.year+'/'+$scope.month+'/'+$scope.startday;
$scope.end=$scope.year+'/'+$scope.month+'/'+$scope.currentday;
$scope.url1=$rootScope.ApiWeatherHost+'/climo/v1/actuals/'+$scope.location_key+'.json?start='+$scope.start+'&end='+$scope.end+'&apikey='+$rootScope.apikey;
$scope.url2=$rootScope.ApiWeatherHost+'/climo/v1/records/'+$scope.location_key+'.json?start='+$scope.start+'&end='+$scope.end+'&apikey='+$rootScope.apikey;
$scope.url3=$rootScope.ApiWeatherHost+'/climo/v1/normals/'+$scope.location_key+'.json?start='+$scope.start+'&end='+$scope.end+'&apikey='+$rootScope.apikey;
变量输出=$(“#输出”);
$('').text($scope.url1).appendTo(输出);
$('').text($scope.url2).appendTo(输出);
$('').text($scope.url3).appendTo(输出);
}({},{ApiWeatherHost:'www.fake-api.com',ApiKey:'12345'})


Ya我也收到了这个。但是当我尝试将该url发送到JSNOP时。。它不起作用了。。我不知道为什么。?@mani-它在开发工具控制台中说了什么?如果您检查返回的HTTP响应是否包含错误?输出即将到来。但它不是JSONP格式。它只提供JSON格式。有时,它还提供JSONP格式作为输出。我不知道这件事。我还与服务器端人员进行了核对。这是一个公共API吗?我不想让你发布你的API密钥,但是如果我可以编写自己的代码来访问API,我可以看到发生了什么?不,它不是公共API。?这是一个私有API密钥。