【问题标题】:Angular button does not show, shows on refresh角度按钮不显示,刷新时显示
【发布时间】:2017-05-09 22:36:52
【问题描述】:

我有一个角度控制器和一个视图。控制器代码如下:

app.controller('someController',
     ['$scope', '$rootScope', '$location', '$routeParams', 'someService',
     function ($scope, $rootScope, $location, $routeParams, someService) {
	
	$scope.dataLoadingComplete = false;
    $scope.hasStarted = true;

	function getSurvey() {
		$rootScope.loadingView = true;
		someService.getSurvey().then(
		   function (results) {
				$rootScope.loadingView = false;
				$scope.dataLoadingComplete = true;
				
				if (results.status === 200) {
					//set other scope variables...
                                                       
                   $scope.totalAnsweredQuestions = results.data.totalAnsweredQuestions;
                    if ($scope.totalAnsweredQuestions > 0)
		   			    $scope.hasStarted = true;
		   		    else
		   			    $scope.hasStarted = false;                                   
				    }
		   },
		   function (error) {
			//log error
			$rootScope.loadingView = false;
			$scope.dataLoadingComplete = true;
				   
			$scope.errorMessage = "Error occurred.";

		   });
	}
	getSurvey();

}]);

在视图中我有以下代码:

<div>
  <p>Some content....</p>
  <div ng-show="dataLoadingComplete">
      <button ng-if="!hasStarted">Start Survey</button>
  </div>
</div>

我遇到了一些问题,一些用户没有看到开始调查的按钮。

【问题讨论】:

  • 'ng-if="!hasStarted"' 你能删除它并测试
  • 我必须根据“已启动”条件显示不同的按钮

    一些内容....

  • 仅出于测试目的将其删除
  • 我并不总是遇到按钮“开始调查”机器人显示的问题。我的应用程序的随机用户没有看到此按钮。所以,如果我删除测试条件,它总是对我有用。在没有任何问题之前我已经对此进行了测试。
  • 任何控制台日志错误?

标签: angularjs variables scope


【解决方案1】:

验证他们没有收到除了 200 或 $scope.totalAnsweredQuestions 为这些客户的 0 以外的响应。如果您在 if ($scope.totalAnsweredQuestions > 0) 内进行 console.log 退出,但他们仍然看不到该按钮,则尝试确定其客户端硬件的差异(较慢的机器,可能是服务响应的竞争条件和客户端渲染页面)或客户端浏览器的差异(他们使用浏览器 X 而您使用的是 Y)

【讨论】:

  • 他们使用的是 iphone,它使用 safari 浏览器。我在我的 iphone 上尝试了同样的方法,我这边没有问题。我猜这可能是互联网连接速度慢或其他原因。但是,即使在那种情况下,它也应该在延迟后显示,对吧?
猜你喜欢
  • 1970-01-01
  • 2018-05-29
  • 1970-01-01
  • 2020-08-02
  • 2011-06-17
  • 2021-10-30
  • 2021-08-22
  • 2013-01-05
  • 1970-01-01
相关资源
最近更新 更多