1

I am trying to capture the querystring and apply the value to my ng-include.

My querystring: http://mydomain.com/?target=W7ROP175T5TEHW2

My MainCtrl: $scope.target = $location.search()['target'];

$scope.target is picking up the value.

Doing a simple text write, ie {{target}} works.

This does not work: <div ng-include="'/_UserSession/{{target}}/assets/menu.html'"></div>

Any ideas?

3
  • Hmmm...I don't think the {{}} are necessary since you're already writing in Angular Commented Sep 9, 2013 at 17:39
  • so what would be the syntax? Cannot be < div ng-include="'/_UserSession/target/assets/menu.html'"> Commented Sep 9, 2013 at 17:40
  • Nope, I'm looking right now, can't seem to find anything relevant tho. If you just do ng-include="target" is target being defined or just plain text? Commented Sep 9, 2013 at 17:41

2 Answers 2

2

You need to escape the value, it is an expression.

ng-include="'/_UserSession/' + target + '/assets/menu.html'"

Also if you want to make sure that target is set before it attempts to include the template, you can add ng-if ="target". This way it will avoid a bad request.

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

1 Comment

Is there a need to call encodeURIComponent on target? I mean in general. Is there a need to URL-esacape concatenated variables or is Angular clever enough to figure out that this is a URL?
1

OK, I solved it, I hope this helps others as well:

HTML

<ng-include src="session()"></ng-include>

Controller

$scope.target = $location.search()['target'];

$scope.session = function() {
    return "/_UserSession/" + $scope.target + "/assets/menu.html";
};

2 Comments

what error did you see in your original post? btw, you can't put a space between < and div, make sure it looks like <div in your code.
I only put the space there because Stackoverflow wouldn't show the line as code

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.