Error when populating the url dynamically


#1

Hi all,

I am using the below code for generating dynamic side bar menus. The menu text works fine. But On the click link (ng-click), I am getting some error which I could not fix.

Below is the HTML code.

< ion-list ng-repeat=“menu in menuData”>
< ion-item nav-clear menu-close ng-click="#/app/{{menu}}">
  {{menu}}
< /ion-item>
< ion-list>

Below is the error that I get. The values are populated as app/blogs but I get error.

Error: [$parse:syntax] Syntax Error: Token ‘app’ is an unexpected token at column 2 of the expression [/app/blogs] starting at [app/blogs].


#2

ng-click requires a function on a scrope something like this:

$scope.navigate = function (page) {
     $location.path(page);
}

<ion-item ng-click="navigate('/app/' + menu)"></ion-item>

In other cases you can use ng-href or ui-sref of ui-router to navigate directly to another state in your template:
https://docs.angularjs.org/api/ng/directive/ngHref


#3

Thanks for the response. It works as required.

Sorry for late response on this.