我在理解路由如何与angular-ui-router和状态一起工作时遇到了一些麻烦。
我有一个基于离子(v1),角度和esri jsapi构建的应用程序。我使用离子侧菜单和angular-ui-router。在加载我的网站时,你会得到地图视图,当使用侧边菜单导航到一个工作站,然后查看一个工作站的细节,然后点击地图按钮缩放到地图上的位置,我做一个$状态.go()到地图视图,您将看到视图/控制器再次初始化。您可以通过查看控制台并查看"创建地图"在初始加载地图视图后再次显示。
我设置了我的状态:
.state('app.map', {
url: '/map',
cache: true,
reload: false,
params: {
attributes: null
},
views: {
'menuContent': {
templateUrl: 'templates/map.html',
controller: 'MapController'
}
}
})
.state('app.detail', {
url: '/detail',
cache: false,
params: {
properties: null
},
views: {
'menuContent': {
templateUrl: 'templates/detail.html',
controller: 'DetailController'
}
}
})
我想避免在从详细视图转换到地图视图时重新实例化地图视图/控制器。我希望从详细信息页面单击按钮以转换到原始地图视图状态,但我怀疑它正在尝试创建另一个地图视图实例。如果我点击地图的侧面菜单按钮,它不会重新初始化,我会得到原始地图视图。
网站:
答案 0 :(得分:0)
尝试通过这些讨论可能会对你有所帮助 https://github.com/angular-ui/ui-router/issues/1758,https://github.com/angular-ui/ui-router/issues/64
此外,如果你在侧面菜单地图选项中使用ng-href工作正常,所以不要使用ng-click而是使用ui-href并调用返回状态名称的函数。像这样的东西;
<ion-item ng-repeat="feature in features | filter: {attributes: {Property: search.input}} as filteredCount"
class="item item-icon-left item-icon-right"
ui-sref={{onListItemClick({"Station_Id":487,"Property":"Neal Blaisdell Center Parking Structure","Street_Address":"777 Ward Avenue","City":"Honolulu","Zip_Code":96814,"Island":"Oahu","In_Use":"No","Charger_Fee_Type":"Free","Charger_Notes":"Enter S. King Street/Victoria street. Follow blue signs to Charger.","Hours_of_Operation":"6:00am-12:00am","Charger_Count":1,"Charger_Port":1,"Charger_Level":2,"Charger_Fee":"Free","Parking_Fee":"Free for EV Drivers","Network":"ChargePoint","Notes":"Activate charger with ChargePoint Network card or call the number listed on the front of the charger for access. ","Latitude":21.299434,"Longitude":-157.850378,"Location":"(21.299434, -157.850378)","Other1":null,"Other2":null,"Other3":null,"Other4":null,"Other5":null,"Other6":null,"Other7":null,"Other8":null,"Other9":null,"Other10":null,"FID":3,"CreationDate":1484871379520,"Creator":"dpascual_HEC","EditDate":1484871379520,"Editor":"dpascual_HEC","Hawaiian_Station":null,"OwnedBy":null,"ChargingStandards":null,"Servicing":null,"ServiceNotes":null}) }}>
</ion-item>
Controller.js
$scope.onListItemClick = function (attributes) {
var data = {
properties: attributes
};
return "app.detail({attributes:"+data+"})" ;
}
我希望这能解决你的问题。