Navigate to another view via $state.go

I am using the Ionic Framework to create a single page app for mobile. I have a tab based structure for the profile page. Inside the "Home" view, I have a link "Edit Profile" once clicked it should navigate to editprofile.html via ProfileManagementController.js. When I click it, nothing happens and no errors show in the console either. Only the url in the address bar gets updated.

Here is the route code in app.js:

.state('editProfile', {
    url: '/editProfile',
    views: {
      'tab-editprofile': {
        templateUrl: 'templates/profile/editprofile.html',
        controller: 'ProfileManagementController'
      }
    }
  })

Here it the ProfileManagementController.js snipper relevant to this feature:

$scope.goToEditProfile = function(path)
{
    $state.go(path);
}

This is the HTMl form for the Home tab view (tab-home.html) in which the button exist to navigate to edit profile :

<div>
          Name: {{tempUserObject.name}} <br/>
          Friends: {{tempUserObject.totalFriends}}<br/>
          Mobile: {{tempUserObject.mobile}}<br/>
          Username: {{tempUserObject.username}} <br/>  
          <br/>
            <button ng-click="goToEditProfile('editProfile')" class="button">Edit Profile</button>

        </div>

This is the URL originally when i first land on tab-home.html and after clicking the button that doesn't work:

Before: http://127.0.0.1:49259/index.html#/tab/home After: http://127.0.0.1:49259/index.html#/editProfile

Please help guide me to figure out what is going wrong with this link. I've used $state.go before in other places and it works well.

Update: editprofile.html added.

<ion-view hide-nav-bar="false" title="Edit Profile">
    <ion-content padding="'true'" class="has-header">
        <div class="spacer" style="width: 300px; height: 87px;"></div>
        <div class="button-bar"></div>
        <h2>Edit Profile</h2>
    </ion-content>
</ion-view>

use this instead of state change.

 $location.path('/editProfile');

Dont forget to inject $location in your controller function.


Do you have a state named 'path' defined in your app.js? If not create a state named 'path' with template and controller just like the 'editprofile' state


所以我解决了上面的问题,修改了app.js中的路由如下:

 .state('editprofile', {
    url: '/editprofile',
    templateUrl: 'templates/profile/editprofile.html',
    controller: 'ProfileManagementController'
  })
链接地址: http://www.djcxy.com/p/77982.html

上一篇: TypeError:不能作为函数调用类

下一篇: 通过$ state.go导航到另一个视图