0

I am trying to call the Alchemy REST API using Angular js. I am embedding the js in HTML and I have posted the code that I am using below.I am trying to display the JSON from the REST API on the HTML page, but I am not getting anything on the page currently. Please let me know what I am doing wrong?

I am new to Javascript and Angular js.

HTML code :-

<!DOCTYPE html>
<!--View-->
<html ng-app="myApp">
<head>
<meta charset="ISO-8859-1">
<title>Using Angular JS</title>
</head>
<body>
    <div data-ng-controller="AngularJSCtrl">
        <input type="text" data-ng-model="name"/>
        Data from server: 
    </div>



<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular-resource.min.js"></script>
<script>

    var myApp = angular.module('myApp',[]);

    <!--Service>
    myApp.service('dataService', function($http) {
    delete $http.defaults.headers.common['X-Requested-With'];
    this.getData = function() {
        // $http() returns a $promise that we can add handlers with .then()
    return $http({
        method: 'GET',
        url: 'http://access.alchemyapi.com/calls/text/TextGetTextSentiment',
        params: 'text=I am taking my insurance and I have heard great things abot nationwide, outputmode=json',
        headers: {'Authorization': 'Token token=ee5379eaf38a3e7931f8f4db39984d6efaf2c75c'}
     });
 }
});


    <!--Controller>                                     
        myApp.controller('AngularJSCtrl', function($scope, dataService) {
        $scope.data = null;
        dataService.getData().then(function(dataResponse) {
        $scope.data = dataResponse;
        console.log('The return value is:' + dataResponse);
    });
});

</script>

</body>
</html>

0 Answers0