2015-06-27 80 views
1

這是我的代碼。我想在用戶點擊「登錄」按鈕時打開一個新頁面。我已經寫了配置功能並且也設置了狀態名。爲什麼我的"applicaion.html"頁面未打開。按鈕點擊不在離子框架中打開新頁面

在控制檯中,我可以看到用戶名稱打印,但$state.go('apps')行不起作用。

[http://codepen.io/skpatel/pen/XbVjKJ][1] 
[1]: http://codepen.io/skpatel/pen/XbVjKJ 

回答

1

看到這個更新的代碼:http://codepen.io/anon/pen/PqEpbR?editors=101

你錯過以下內容的index.html:添加引用ui-view(從UI路由器)正在管理的看法的變化。 你的代碼在index.html中是靜態的,沒有引用新頁面。

Ui視圖已添加到index.html。這是ui-router指令,並且是強制性的。離子使用UI路由器

<body> 
    <div ui-view></div> 
</body> 

我已經放出來的登錄頁面的代碼放到一個腳本模板:

<script type="text/ng-template" id="home.html"> 

    <ion-header-bar class="bar-calm"> 
     <h1 class="title">Application Permissions</h1> 
    </ion-header-bar> 
    <ion-content padding="true" has-header="true" padding="true" ng-controller="HomeCtrl"> 
     <p>Welcome to the privacy mirror home page!</p> 
     <p>Enter your name and then you can just tap the login button to be logged in</p> 
     <label class="item item-input" class="padding"> 
      <input type="text" placeholder="Username" ng-model="user.username" required> 
     </label> 
     <div class="padding"> 
      <button class="button button-block button-stable" ng-click="login()">Login</button> 
     </div> 
    </ion-content> 
</script> 

又創造了apps.html t emplate:

<script type="text/ng-template" id="apps.html"> 

    THIS IS MY APP PAGE 
</script> 

最後,有要更新的路由規則指向home.html

.state('home', { 
       url: '/home', 
       templateUrl: 'home.html', 
       controller: 'HomeCtrl' 
      }) 
+0

謝謝讓我試試我自己 –

+0

根據本教程,它不是強制要放'ui-view'。爲什麼?我對這項技術是全新的,對於愚蠢的問題感到抱歉 –

+0

我編輯了我的回覆,其中包括ui-view部分 – aorfevre