0

I have the following problem with angularjs and spring-data-rest. I want to create a view for a fee. so in my html i have a fee table with different fees.

            <table class="table table-striped table-bordered table-hover">
                <thead>
                    <tr>
                        <th>Name</th>
                        <th>Setup in <i class="glyphicon glyphicon-euro"></i></th>
                        <th>Basic Period</th>                           
                        <th class="text-right">{{ 'ACTIONS' | translate }}</th>
                    </tr>
                </thead>
                <tbody>
                    <tr ng-repeat="fee in billing">
                        <td>{{ fee.name }}</td>
                        <td><span ng-hide="editMode">{{ fee.setupAmountEur }}</span></td>
                        <td><span ng-hide="editMode">{{ fee.basic.period }}</span></td>
                        <td>
                            <a class="btn btn-info pull-right" href="{{fee._links.self.href}}">{{ 'FEES_LINK' | translate }}</a>
                        </td>
                    </tr>
                </tbody>
            </table>

When i click on the FEES_LINK the browser shows the plain json. What i want is to have a new html site. So i dont know how i can do the angular http.get to my self link?

Can someone help, please?

Markus Streicher
  • 133
  • 1
  • 1
  • 10

1 Answers1

0

_links.self.href is a technical link telling the application about the possible transitions/operation on the current resource. By design it is returning a representation of the resourced identified by the URI. A resource may have serveral possible representation. JSON, XML or HTML.

More on hypermedia links see https://books.google.ch/books?id=ZXDGAAAAQBAJ&printsec=frontcover&dq=rest+web+api&hl=en&sa=X&ved=0CDAQ6AEwAGoVChMIi4LXsNjTyAIVTNYUCh2D1QEq#v=onepage&q=rest%20web%20api&f=false

The server should return the correct representation format according to the Accept header.

application/json should return JSON. application/xml should return XML and text/html should return HTML format.

About your problem I'd just wrap the link in a function and get the data via $http.

<a class="btn btn-info pull-right" ng-click="load(fee._links.self.href)">{{ 'FEES_LINK' | translate }}</a>

$scope.load = function(url) {
    $http.get(url).then(function(response) {
         // show data in popup or new page.........
    });
}
Michael
  • 3,085
  • 1
  • 17
  • 15
  • can i send this link in `_links.self.href` to an other controller? or how can i get a new html site for this? thx – Markus Streicher Oct 21 '15 at 13:48
  • Technically `_links.self.href` is just a String. It's up to you what you do with it. You can store it in Scope or send it to another controller. That depends on what you want to do with it. – Michael Oct 21 '15 at 14:05
  • I want to show it in a new page with a new controller. So how can i send the `_links.self.href` to it? Thats the question. Sorry im working the first time with angular and spring data and need a fast solution. – Markus Streicher Oct 21 '15 at 14:33
  • That's difficult without knowing your setup. Do you use an Angular router? Do you use views? Do you have nested controllers?.... Anyway the simplest solution is to the URL in the `rootScope`. There you can access it from anywhere - also from another controller. – Michael Oct 21 '15 at 15:18
  • thats what i am looking for: http://stackoverflow.com/questions/20181323/passing-data-between-controllers-in-angular-js in comination with your code. thx – Markus Streicher Oct 22 '15 at 08:00