0

We have a legacy application using struts 1 and we would like to use angularJS as a front end framework for some pages. So how to integrate AngularJS within this application ?

Some steps to follow in order to start using angularJS with struts would be heplful.

Thanks

kkung
  • 715
  • 4
  • 10
  • 18

1 Answers1

1

Some simple example for AngularJS code given below,

In HTML add the module name and source file,

<html lang="en" data-ng-app="App_Name">
<src="../your_path/angular.min.js"> //Javascript file

In Script load the module and use $http function call the servlet,

angular.module('App_Name', [])
    .controller('App_Controller', ['$scope','$http', function($scope, $http) {

    $http.post('http://localhost:8080/URL.do').
       success(function(data, status, headers, config) {
         //console.log(data);
         $scope.myVar = data;   //Assign to AngularJS Variable
     }).
     error(function(data, status, headers, config) {
         //console.log(data);
     });
}]);

Inside body,

<body data-ng-controller="App_Controller">..</body>

Hope this helps.

Vinoth Krishnan
  • 2,925
  • 6
  • 29
  • 34