无法通过Angular-controller

时间:2017-05-05 12:03:29

标签: javascript angularjs

我正在使用api调用数据 - 我的设置包括angularjs,所以我试图通过控制器调用,但是有些数据或事件没有响应。

所以这是我的代码:



myApp.controller('someAppController',['$scope', '$http','$state','apiUrl','$q','$timeout','$interval', function ($scope, $http, $state,apiUrl,$q,$timeout,$interval) {
      var apiURL = apiUrl+"fetchData";
      $scope=this;        
      
			$scope.fetchAppData = function(device,os){
			$scope.dt = device;	
			$scope.platform = os;
			$scope.startDate = $('#sDate').val();
			$scope.endDate = $('#eDate').val();
			 var startDate = $scope.startDate;
			 var endDate = $scope.endDate;
			 var deviceType = $scope.dt;
			 var oSystem = $scope.platform;
			 var appKey = localStorage.getItem("appKey");
			 var i;
			var dfrd = $q.defer();
			$http.get(apiURL, 
				{
					params:{type: deviceType, platform : oSystem, sd: startDate, ed: endDate, akey: appKey},
			
      
				}
			)
			.then(function(response) {
				$scope.users = response.data;
				var data = response.data;
				for(var i = 0; i<data.length; i++){
					var tts = data[i].tts;
					var ts = data[i].ts;
					var nuu = data[i].nuu;
					var atsps = data[i].tts / data[i].ts;
					var atsbu = data[i].tts / data[i].nuu;
					
					if ( isNaN(atsps)||  atsps == Number.POSITIVE_INFINITY || atsps == Number.NEGATIVE_INFINITY || atsps === null)
						{	//console.log("false atsps" +atsps);
							data[i].atsps = 0;
						}
					else{
						data[i].atsps = atsps; 
					}
					if ( isNaN(atsbu) || atsbu == Number.POSITIVE_INFINITY || atsbu == Number.NEGATIVE_INFINITY || atsbu === null)
						{
							//console.log("false atsbu" +atsbu);
							data[i].atsbu = 0;
						} 
					else{ 
						
							data[i].atsbu = atsbu;
						}
				}
			$scope.users = data;
				
			}, function(x) {
				dfrd.reject(true);
			});
			return dfrd.promise;
			
	 };
 $scope.cb= function(start, end){
    $('#dateRangescreenAnalytics span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
    startDateCal = start;
    endDateCal = end;
    $scope.fetchAppData($scope.dt,$scope.platform);
}
  
 $scope.cb(moment().subtract(29, 'days'), moment());
   

$('#dateRangescreenAnalytics').daterangepicker({
    ranges: {
       'Today': [moment(), moment()],
       'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
       'This Week': [moment().startOf('week'), moment().endOf('week')],
       'Last Week': [moment().subtract(1, 'week').startOf('week'), moment().subtract(1, 'week').endOf('week')],
       'This Month': [moment().startOf('month'), moment().endOf('month')],
       'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
},
locale: {
    format: 'YYYY-MM-DD',
    applyLabel: "Select"
 },
startDate: startDateCal,
endDate: endDateCal
}, $scope.cb);


}]);
&#13;
<div ng-controller="someAppController as deviceCtrl">
		<div class="wrapper">
		<div class="page">
			<div class="row breadcrumb bg-white border-bottom paddl30">
				<div class="col-md-6">
					<ul>
						<li><a href="">Voices</a></li>
						<li> &gt; </li>
						<li>Datas</li>
					</ul>
				</div>
			</div>
				<div class="row bg-white border-bottom">

					<div class="col-md-12">
						<div class="photos" autofocus>
							<img ng-repeat="user in deviceCtrl.users" class="cover" data-name="{{user.name}}" ng-src="{{user.path}}"/> 
		
						</div><!-- End of Photos -->
						<div id="photos-info">
							<div id="photos-name"></div>
						</div>
					</div> <!-- End of col md 12 -->

				</div><!-- End of row -->
				<div class="carousel-info text-right col-md-12">
						<p>Use arrow < > keys or mouse scroll to view carousel.</p>
					</div>
					
				<div class="row">
					<ul class="info-container" ng-repeat="user in users" style="display:none">
						<li class="col-xs-12 col-sm-4 col-md-2">
							<div class="info">
								<div class="col-xs-12"><h3>Number of unique users</h3></div>
								<div class="col-xs-12"><p>{{deviceCtrl.user.nuu}}</p></div>
							</div>
						</li>
						<li class="col-xs-12 col-sm-4 col-md-2">
							<div class="info">
								<div class="col-xs-12"><h3>number of crashes</h3></div>
									<div class="col-xs-12"><p>{{deviceCtrl.user.noc}}</p></div>
							</div>
						</li>
						<li class="col-xs-12 col-sm-4 col-md-2">
							<div class="info">
								<div class="col-xs-12"><h3>total time spent</h3></div>
									<div class="col-xs-12"><p>{{deviceCtrl.user.tts |secondsToHHmmss}}</p></div>
							</div>
						</li>
						<li class="col-xs-12 col-sm-4 col-md-2">
							<div class="info">
								<div class="col-xs-12"><h3>Average Time spent by user</h3></div>
									<div class="col-xs-12"><p>{{deviceCtrl.user.atsbu |secondsToHHmmss}}</p></div>
							</div>
						</li>
						<li class="col-xs-12 col-sm-4 col-md-2">
							<div class="info">
								<div class="col-xs-12"><h3>Total sessions</h3></div>
									<div class="col-xs-12"><p>{{deviceCtrl.user.ts}}</p></div>
							</div>
						</li>
						<li class="col-xs-12 col-sm-4 col-md-2">
							<div class="info">
								<div class="col-xs-12"><h3>Average time spent per sessions</h3></div>
								<div class="col-xs-12"><p>{{ deviceCtrl.user.atsps |secondsToHHmmss}} </p>
								</div>
							</div>
						</li>
					</ul>
				</div>
			</div>	
			</div>
</div>		 
&#13;
&#13;
&#13;

所以基本上

*

<div class="row">
                    <ul class="info-container" ng-repeat="user in users" style="display:none">
                        <li class="col-xs-12 col-sm-4 col-md-2">
                            <div class="info">
                                <div class="col-xs-12"><h3>Number of unique users</h3></div>
                                <div class="col-xs-12"><p>{{deviceCtrl.user.nuu}}</p></div>
                            </div>
                        </li>
                        <li class="col-xs-12 col-sm-4 col-md-2">
                            <div class="info">
                                <div class="col-xs-12"><h3>number of crashes</h3></div>
                                    <div class="col-xs-12"><p>{{deviceCtrl.user.noc}}</p></div>
                            </div>
                        </li>
                        <li class="col-xs-12 col-sm-4 col-md-2">
                            <div class="info">
                                <div class="col-xs-12"><h3>total time spent</h3></div>
                                    <div class="col-xs-12"><p>{{deviceCtrl.user.tts |secondsToHHmmss}}</p></div>
                            </div>
                        </li>
                        <li class="col-xs-12 col-sm-4 col-md-2">
                            <div class="info">
                                <div class="col-xs-12"><h3>Average Time spent by user</h3></div>
                                    <div class="col-xs-12"><p>{{deviceCtrl.user.atsbu |secondsToHHmmss}}</p></div>
                            </div>
                        </li>
                        <li class="col-xs-12 col-sm-4 col-md-2">
                            <div class="info">
                                <div class="col-xs-12"><h3>Total sessions</h3></div>
                                    <div class="col-xs-12"><p>{{deviceCtrl.user.ts}}</p></div>
                            </div>
                        </li>
                        <li class="col-xs-12 col-sm-4 col-md-2">
                            <div class="info">
                                <div class="col-xs-12"><h3>Average time spent per sessions</h3></div>
                                <div class="col-xs-12"><p>{{ deviceCtrl.user.atsps |secondsToHHmmss}} </p>
                                </div>
                            </div>
                        </li>
                    </ul>
                </div>

*

部分代码没有响应?!虽然,它应该显示价值。 任何帮助赞赏。感谢

1 个答案:

答案 0 :(得分:0)

似乎你错过了调用你的方法。 在控制器的末尾添加:

$scope.fetchAppData();