0

I'm passing a query string to a function, which 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 = <a href='#' ng-click='OpenUrl(" + url + ")'>MY LINK </a>"
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?

1
  • Sorry, it is hard to understand what you are trying to do? you want to pass an URL as a paramter to ng-click? and then, what is your goal: open a new browser-tab with this URL? Commented May 11, 2015 at 15:45

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

3 Comments

I need to fire an ng-click when I do <a href='#' ng-click ='GotoUrl('www.cnn.com')'>CNN</a> I get $santize:badparse
what is GotoUrl()? a JS function you wrote and put on $scope? if yes, please show it to us (edit your question)
the error you get simply says the that the string you pass to $compile is not valid HTML, which is true: you are passing it a URL without any tags. docs.angularjs.org/error/$sanitize/badparse so, you should not $compile your URL

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.