2

Below is my angularJS code present in app.js:

'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);
       });
}]);

Below is my html page which basically use the data retrieved from api call in app.js :

<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>

I am integrating the angular page as a link in some other jsp page.Below is how i am adding the link in my jsp page in Liferay:

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

I am integrating the angular page as a embedded link and adding the email and msgChat parameter to that link.But don't know why when I click on the link, my page loads twice once with the parameters and once without the parameters.

PS: I am using liferay and writing the frontend in jsp file.

Laker
  • 1,622
  • 4
  • 20
  • 32
Srijan Sharma
  • 683
  • 1
  • 9
  • 19
  • none of this code has anything to do with page loading; this is all code that is executed after page load, but doesn't affect the load process. – Claies Dec 30 '17 at 17:29
  • @Claies So can you guide me as to what part of code would help? – Srijan Sharma Dec 30 '17 at 17:30
  • without seeing your entire code base, I can only make guesses. What does "integrating the angular page as an embedded link" mean? Is it present on some other page? What file is this code included as a part of? What does your HTML look like? What you have given so far is nowhere near a [mcve] of your setup. – Claies Dec 30 '17 at 17:33
  • I'm not sure why this would happen since you're explicitly defining 'POST' unless there is some sort of redirect happening in between your POST and an unprompted second request in your app. Check this out: https://stackoverflow.com/questions/33017849/angularjs-http-post-firing-get-request-instead-of-post – Harish Vangavolu Dec 30 '17 at 17:36
  • Maybe is not charge twice, it just charges the first time without data and you have to wait for the request fill your template from the promise. You'd create an angular route for when the data is filled, route it to your new `messageFunnel` state. – Kenry Sanchez Dec 30 '17 at 18:16
  • https://github.com/angular-ui/ui-router/wiki/Quick-Reference – Kenry Sanchez Dec 30 '17 at 18:18

1 Answers1

-1

Maybe is not charge twice, it just charges the first time without data and you have to wait for the request fill your template from the promise. You'd create an angular route for when the data is filled, route it to your new messageFunnel state.

You should review this https://github.com/angular-ui/ui-router/wiki/Quick-Reference

Kenry Sanchez
  • 1,703
  • 2
  • 18
  • 24