角UI路由器离子应用程序无法正常工作 [英] Angular-UI router not working in Ionic app

查看:98
本文介绍了角UI路由器离子应用程序无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用离子型框架的应用程序时遇到了问题尝试使用角UI路由器。下面完美的功能code的第一块。然而,当我删除 NG-控制器=LoginController中作为登录并移动到这一点控制器 controllerAs 在路线没有我的角度code的我认为作品中的属性了。我想我明白了路由,但这个问题被绊倒了我。

应用程序/登录/ login.html的:

 <离子查看查看标题=登陆GT&;
  <离子含量NG控制器=LoginController中作为登录>    电子邮件:<输入类型=文本NG模型=login.email>
    密码:LT;输入类型=文本NG模型=login.password>    < BR>< BR>    <按钮NG点击=login.createUser()>创建用户和LT; /按钮>    < BR>< BR>    <按钮NG点击=login.removeUser()>删除用户< /按钮>    < p NG-IF =login.message>消息:LT;强> {{login.message}}< / STRONG>< / P>
    < p NG-IF =login.error>错误:其中;强> {{login.error}}< / STRONG>< / P>
  < /离子含量>
< /离子视图>

code,似乎打破我的观点,app.config.js:

 
  .module(应用)
  的.config(函数($ stateProvider,$ urlRouterProvider){
    $ stateProvider    .STATE('应用',{
      网址:'/应用程序',
      摘要:真实,
      templateUrl:应用程序/布局/ menu.html
    })    .STATE('登陆',{
      网址:'/登录',
      templateUrl:应用程序/登录/ login.html的,
      控制器:'LoginController中',
      controllerAs:登录
    })
...


解决方案

尝试

  .STATE('登陆',{
  网址:'/登录',
  templateUrl:应用程序/登录/ login.html的,
  控制器:'LoginController中作为登录
})

I'm working on an app using the Ionic Framework and am having trouble attempting to use the Angular-ui router. The first block of code below functions perfectly. However, as soon as I remove ng-controller="LoginController as login" and move this into controller and controllerAs attributes in my route none of the Angular code within my view works anymore. I thought I understood routing, but this issue is tripping me up.

app/login/login.html:

<ion-view view-title="Login">
  <ion-content ng-controller="LoginController as login">

    Email: <input type="text" ng-model="login.email">
    Password: <input type="text" ng-model="login.password">

    <br><br>

    <button ng-click="login.createUser()">Create User</button>

    <br><br>

    <button ng-click="login.removeUser()">Remove User</button>

    <p ng-if="login.message">Message: <strong>{{ login.message }}</strong></p>
    <p ng-if="login.error">Error: <strong>{{ login.error }}</strong></p>
  </ion-content>
</ion-view>

Code that seems to "break" my view, app.config.js:

angular
  .module('app')
  .config(function($stateProvider, $urlRouterProvider) {
    $stateProvider

    .state('app', {
      url: '/app',
      abstract: true,
      templateUrl: 'app/layout/menu.html'
    })

    .state('login', {
      url: '/login',
      templateUrl: 'app/login/login.html',
      controller: 'LoginController',
      controllerAs: 'login'
    })
...

解决方案

try

.state('login', {
  url: '/login',
  templateUrl: 'app/login/login.html',
  controller: 'LoginController as login'
})

这篇关于角UI路由器离子应用程序无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆