簡體   English   中英

AngularJS頁面加載兩次

[英]AngularJS page loading twice

下面是app.js中存在的我的angularJS代碼:

'use strict';
var app = angular.module('app', ['slick']);
app.config(['$locationProvider', function($locationProvider) {
    $locationProvider.html5Mode({
        enabled: true,
        requireBase: false
    });
}])

app.
controller('messageFunnel',['$scope', '$http', 
'$location',function($scope, $http, $location) {
    var msgChat = $location.search().msgChat;
    var email   = $location.search().email;
    var url = $location.absUrl();
    url = url.substring(0, url.indexOf('msgChat'));
    $scope.url = url;
    $http({
        method: 'POST',
        url: 'url',
        data: {
            "msgChat": msgChat,
            "email" : email
        }
    }).then(function successCallback(response) {
           $scope.data = response.data;
           console.log($scope.data)
       }, function errorCallback(response) {
              console.log(response.data);
       });
}]);

以下是我的html頁面,該頁面基本上使用從app.js的api調用檢索的數據:

<body>
<div class="row" ng-app="app" ng-controller="messageFunnel">
<div class="col-lg-4 col-md-6 col-sm-12">
  <div class="white-box">
    <h3 class="box-title">Prior</h3>
    <div class="comment-center">
      <div class="comment-body b-none" ng-repeat="item in data.messages[0].prevArray">
        <div class="mail-contnet">
          <span class="time">{{item.count}}</span>
          <a href="{{scope.url}}msgChat={{item.chat}}" target="_blank"><i class="fa fa-external-link fa-pull-right" aria-hidden="true" style = "font-size:15px;"></i></a>
          <br/>
          <p>{{item.chat}}</p>
        </div>
      </div>
    </div>
  </div>
</div>

我正在將角度頁面集成為其他jsp頁面中的鏈接。以下是我如何在Liferay的jsp頁面中添加鏈接:

var link = "Current Page URL";
link = link + '&email=' + email+'&msgChat=' + message;//appending parameters to the url
<A href= link target="_blank">Message value</A>

我正在將角度頁面集成為嵌入式鏈接,並向該鏈接添加email和msgChat參數。但是不知道為什么當我單擊鏈接時,我的頁面兩次加載有參數而一次沒有參數。

PS:我正在使用liferay,並在jsp文件中編寫前端。

也許不用兩次收費,它只是在沒有數據的情況下第一次收費,您必須等待請求從承諾中填充您的模板。 您將為填充數據時創建一個角度路由,將其路由到新的messageFunnel狀態。

您應該查看此https://github.com/angular-ui/ui-router/wiki/Quick-Reference

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM