Call actions / references to invoas in form action with method message

We use hateoas

to call our links. Our HateoasWrapper looks like this (copied from the browser console):

{
    $actions: [
        {
            $call: function ()
            action: "load"
            href: "http://myApi"
            method: "POST"
            rel: "parent"
        }
    ],
    $load: function (),
    Links: [
        {
            ActionValue: "load"
            Href: "http://myApi"
            Methid: "POST"
            Reld: "parent"
        }
    ]
}

      

So we can just call our links like this: myObject.$load()

(it calls the href from download). This works great.

Now I am trying to call $load()

in an action

element form

. To do this, I put a call in action

and run it with the submit

following:

<form action="ctrl.myObject.$load()" method="post" target="_blank">
    <input type="submit">
</form>

      

This does not work. It opens a new tab, but with this error:Cannot post/ctrl.myObject.$load()

When I put the href hardcoded on the action, it works (new tab with correct data):

<form action="http://myApi" method="post" target="_blank">
    <input type="submit">
</form>

      

Can I call hateoas

action

in form

as my solution?

+3


source to share


1 answer


You don't need interpolation here. Since it is action

not a standard AngularJS directive / attribute, the passed expression cannot be understood by the AngularJS engine.

Try to wrap the expression ctrl.myObject.$load()

in curly braces like this {{ctrl.myObject.$load()}}

, and then AngularJS will automatically replace it with the function's return value.

Watch it in action in the next snippet. Open the control panel and see what's in the attribute action

.



angular.module("myapp", [])
  .controller("myCtrl", function($scope) {
    $scope.myaction = function() {
      return "abc";
    };
  });
      

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

<div ng-app="myapp" ng-controller="myCtrl">
<form action="{{myaction()}}">
  Inspect this form action in console
</form>
</div>
      

Run code


0


source







All Articles