JavaScript runtime error: [$parse:lexerr] Lexer Error: Unexpected next character at columns 128-128 [&] in

Problem

I'm passing a querystring to a function - which then gets $compiled that opens a new window. I get the following error

  • JavaScript runtime error: [$parse:lexerr] Lexer Error: Unexpected next character at columns 128-128 [&]

var url = 'http://.....?&filename=123.doc&user=Bob'

var html = MY LINK "

var link = $compile(html)($scope)

the function just opens a new window . It doesn't seem to like the '&'

I'm $compiling the url and expression so it can be used in an ng-click

Any ideas what I'm doing wrong?

Problem courtesy of: Jon

Solution

why do you $compile the URL, I don't see why this would be needed. $compile in angular does not compile URLs, it compiles an HTML-String or a DOM-tree and compiles/links angular directives that are used in this HTML.

Is this solving your issue?

in the controller:

$scope.myUrl =  "http://... ";

in the HTML:

 <a ng-href="{{myUrl}}" target="_blank">blabla</a>
Solution courtesy of: Reto

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.