4

I have spring controller defined as

@Controller
public class TestController {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @RequestMapping(value="/hello")
    public String home(HttpServletRequest httpRequest, Model model) {        

            model.addAttribute("Authorization", "test string");

            return "/index";
    }  
}

Is there any way I could get attribute "Authorization" in angularjs controller?

2
  • What does the /index view do with this attribute? Typically, angular controllers get their data from JSON HTTP responses. Commented Jan 13, 2015 at 19:26
  • @JBNizet index.html is a html file binding with angularjs controller. "Authorization" attribute needs to be used in angularjs controller to make another post call. Commented Jan 13, 2015 at 19:36

4 Answers 4

1

Try this:

($location.search()).Authorization

More details about $location and parameters: https://docs.angularjs.org/api/ng/service/$location

Sign up to request clarification or add additional context in comments.

2 Comments

I am not able to use model attribute in angularjs using this
More examples please, I want to convert my spring controller to angular
1

try ng-init="var = ${Authorization}" then in controller $scope.var

Comments

0

I've faced with the same issue, but ($location.search()).attributeKey doesn't work for me. In my angularJs controller I'm receiving 'undefined' value via ($location.search()).attributeKey.

Comments

0

I had this problem for some time . I used a 'hackish' way to access a variable added as a modal attribute in the backend .

let say you have added "some-data" to the model like follows.

model.addAttribute("some-data-id", "some-data");

in the jsp where the ctrl is initializing add the attribute to a hidden html element such as a span

<span style="display:none" id="someDataId">${some-data-id}</span>

and in the controller , retrieve the value using angular.element('#some-data-id').innerHTML

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.