Below is my requirement.
I have an ionic app. Initially on the landing page, i am loading some content along with Menu.
In the Menu, there are some items with route params function call?
Initially when the page loads, route params will be blank and below is the error i am getting:
Error: [$parse:syntax] Syntax Error: Token '}' not a primary expression at column 10 of the expression [{brandID:}] starting at [}]. http://errors.angularjs.org/1.2.25/$parse/syntax?p0=%7D&p1=not%20a%20primary%20expression&p2=10&p3=%7BbrandID%3A%7D&p4=%7D at VALIDITY_STATE_PROPERTY (http://localhost:8100/lib/ionic/js/ionic.bundle.js:7703:12)
Template:
<ion-item nav-clear menu-close ui-sref="app.brandFeedback({brandID:{{menu_brand_id}}})" ng-show = "brand_spec_menu_item"> Talk to the Brand </ion-item>
App.js
.state('app.brandFeedback', {
url: "/brands/:brandID/brandFeedback",
views: {
'menuContent' :{
templateUrl: "partials/brand_feedback.html",
controller:'BrandFeedbackCtrl'
}
}
})
Later when navigating to other pages. I will assign the ID based on the route params available on that page.
How to handle the blank or null initially in the template?
Your problem isn't directly due to the null value; it's the syntax you're using in the ui-sref
attribute. You have
ui-sref="app.brandFeedback({brandID:{{menu_brand_id}}})"
But the double braces in the expression are wrong; what you really want is
ui-sref="app.brandFeedback({brandID: menu_brand_id})"
Assuming that menu_brand_id
is a variable that will at least sometimes be passed to the template's scope. If menu_brand_id
does not exist, though, you still won't get an error; the app.brandFeedback
function will be called with the argument {brandID: undefined}
.