angularjs - Angular url 配置不适用于 ionic 框架

标签 angularjs angular-ui-router hybrid-mobile-app ionic-framework

当我加载应用程序时,我试图从模板文件夹获取仪表板 View 。我正在使用 Ionic 框架。

我的索引

  <body ng-app="starter">

<ion-pane>
  <ion-header-bar class="bar bar-header bar-dark main-header">
    <h1 class="title main-header-title"><strong>Recharge Plans</strong></h1>
  </ion-header-bar>
  <ion-nav-view></ion-nav-view>
</ion-pane>

我的app.js

    angular.module('starter', ['ionic','starter.controller','starter.service'])

.config(function($stateProvider, $urlRouterProvider) {

$stateProvider
  .state('dash', {
    url: '/dash',
    views: {
      'dash': {
        templateUrl: '/templates/dash.html',
        controller: 'DashCtrl'
      }
    }
  });
$urlRouterProvider.otherwise('/dash');
});

我的controller.js

    angular.module('starter.controller',[])

.controller('DashCtrl', function($scope) {
alert("ok");
})

在“www\templates”中,我有一个名为 dash.html 的文件。

我的 dash.html 是

<ion-view ng-controller="DashCtrl">
  <ion-content>
        <div class="list searc-panel">
            <label class="item item-input item-select">
                <div class="input-label">
                  Select Operator
                </div>
                <select>
                  <option>Select</option>
                  <option>Airtel</option>
                  <option>Vodafone</option>
                </select>
            </label>            
            <label class="item item-input item-select">
                <div class="input-label">
                  Select State
                </div>
                <select>
                  <option>Select</option>
                  <option>West bengal</option>
                  <option>Kolkata</option>
                </select>
            </label>
            <button class="button button-full button-positive">
              Search My Plans
            </button>
        </div>
  </ion-content>
</ion-view>

但是当我在浏览器中点击“file:///C:/Users/Sanjeev/RechargePlans/www/index.html”时,它会将我呈现为“file:///C:/Users/Sanjeev/RechargePlans/” www/index.html#/dash' 带有空白 View 。

我想念什么?

最佳答案

如果您要使用 Ionic 命名 View ,那么您的 ion-view 选项卡 HTML 需要如下所示:

<ion-nav-view name="you-view-name"></ion-nav-view>

通常,使用 Ionic 应用程序时,您有一个根状态,一切都源于此,因此:

app.js 文件:

angular.module('starter', ['ionic','starter.controller','starter.service'])

    .config(function($stateProvider, $urlRouterProvider) {

        $stateProvider
            .state('root', {
                url: '/',
                templateUrl: '/templates/tabs.html',
                controller: 'rootCtrl'
                }
             });
            .state('root.dash', {
                url: '/dash',
                views: {
                    'dash': {
                        templateUrl: '/templates/dash.html',
                        controller: 'DashCtrl'
                     }
                }
             });
         $urlRouterProvider.otherwise('/dash');
     });

index.html:

<ion-nav-view></ion-nav-view>

tabs.html:

<ion-nav-view name="dash"></ion-nav-view>

无论如何,如果您要命名 View ,您的 ion-view HTML 标记需要有一个 name 属性,其中包含 View 的名称。

希望这有帮助

关于angularjs - Angular url 配置不适用于 ionic 框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28935794/

相关文章:

angularjs - 将 ngInclude 与 ControllerAs 语法结合使用的最佳实践是什么?

mysql - 关于在 SPA Angular 中使用 UML 的几个问题

javascript - AngularJS body 函数随机关闭

javascript - 如何更改注销按钮以 Angular 登录

angularjs - 如果仅更改参数,阻止 Angular ui路由器重新加载状态的模板和 Controller ?

angularjs - Angular Hash 与 Hashbang

angular - 错误: both async and sync fetching of the wasm failed

android - 视口(viewport)单位在 Cordova 移动应用程序中不起作用

ios - Meteor.isCordova 和服务器端

css - 更改 Angular Material Design 标签文本的颜色(Angular 1.3.0 和 ngMaterial 0.11)