2016-12-14 296 views
0

I've placed a below link in my code角JS <a href> route back to LogIn

<a href="/#/list/' + data._id + '" class="btn btnprimary1" > LIST </a> 

It should routed to below point

.state('index.list', { 
      url: '/list/:id', 
      templateUrl: '/list.html', 
      data: { pageTitle: 'listing', pageFilter: 'off' }, 
      controller: 'listController', 
      }); 

Instead of that it routed to the main page /# and from that it checks login and rerouted to my current page

Is it a correct way to place href in angular code to route to a state with specific Id.

回答

2

You should use ngHref

<a ng-href="/#/list/{{data._id}}"></a> 

或者最好ui-sref

<a ui-sref="index.list({id: data._id})"></a> 
+0

喔人...感谢 –

+0

它的工作,但你能提供给我更好地理解为什么发生.. –

+1

@AbhishekParikh你的href属性的值是没有棱角的表达式,将解析和编译。它缺少double {{..}}(它甚至不是一个有效的js表达式,请看引号!)。 ng-href和ui-sref是不同的,因为这些都是指令。 – hansmaad

1

您应该使用休耕的方式

<a ng-href="/#/list/{{data._id}}">LIST</a> 
1

你应该到位角href标记的使用NG-HREF指令。

<a ng-href="http://127.0.0.1/projectFolder/#/list/{{data._id}}" class="btn btnprimary1"> LIST </a> 
相关问题