AngularJS - 通过$ state.go导航到另一个视图

时间:2015-11-28 09:06:50

标签: angularjs ionic-framework

我正在使用Ionic Framework为移动设备制作单页应用。我有一个基于标签的结构页面。在“主页”视图中,我有一个链接“编辑配置文件”,一旦点击它应该通过ProfileManagementController.js导航到editprofile.html。当我点击它时,没有任何反应,控制台也没有显示错误。只有地址栏中的网址会更新。

以下是app.js中的路线代码:

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

这里是与此功能相关的ProfileManagementController.js片段:

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

这是主页选项卡视图(tab-home.html)的HTMl表单,其中存在用于导航以编辑配置文件的按钮:

<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>

这是我第一次登陆tab-home.html并点击无法使用的按钮后的网址:

  

之前:http://127.0.0.1:49259/index.html#/tab/home   之后:http://127.0.0.1:49259/index.html#/editProfile

请帮助指导我找出此链接出现的问题。我之前在其他地方使用过$ state.go,效果很好。

更新:editprofile.html已添加。

<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>

3 个答案:

答案 0 :(得分:1)

使用此而不是状态更改。

 $location.path('/editProfile');

别忘了在你的控制器功能中注入$ location。

答案 1 :(得分:0)

你的app.js中是否有一个名为'path'的州? 如果没有像'editprofile'状态那样用模板和控制器创建一个名为'path'的状态

答案 2 :(得分:0)

所以我修改了上面的问题,将app.js中的路由修改为以下内容:

 .state('editprofile', {
    url: '/editprofile',
    templateUrl: 'templates/profile/editprofile.html',
    controller: 'ProfileManagementController'
  })
相关问题