Pop Up 和 ion-nav-view 不能一起工作
Popup and ion-nav-view don't work togehter
我有新手问题。
我的应用程序需要一些非常基本的 AngularJS。我使弹出窗口工作,然后添加了 ion-nav-view。这两个元素都起作用,但不是同时起作用。现在 ion-nav-view 工作完美,但是当我改变
body ng-app="starter"
到
body ng-app="starter" ng-controller="PopupCtrl"
应用变成空白网站。
这一定是一些小错误,但我找不到它在哪里。谁能帮我?我的 app.js:
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
});
})
angular.module('starter', ['ionic'])
.controller('PopupCtrl', function($scope, $ionicPopup, $timeout) {
$scope.showAlert = function() {
var alertPopup = $ionicPopup.alert({
title: 'Alert',
template: 'Alert text'
});
};
});
angular.module('starter', ['ionic'])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('list', {
url: '/1',
templateUrl: 'list.html'
})
.state('info', {
url: '/2',
templateUrl: 'info.html'
})
$urlRouterProvider.otherwise("/1");
})
编辑:
index.html 的正文部分:
<body ng-app="starter" ng-controller="PopupCtrl">
<ion-nav-bar class="bar-positive" align-title="center">
</ion-nav-bar>
<ion-nav-view class="slide-left-right"></ion-nav-view>
<script id="list.html" type="text/ng-template">
<ion-view title="title">
<ion-nav-buttons side="right">
<button class="button button-icon icon ion-android-locate" ng-click="showAlert()"></button>
</ion-nav-buttons>
<ion-content>
<div class="list">
<a class="item item-thumbnail-left" href="#">
<img src="cover.jpg">
<h2>Pretty Hate Machine</h2>
<p>Nine Inch Nails</p>
</a>
<a class="item" ui-sref="info">
<p>Żeby uzyskać pomoc, dotknij to pole.</p>
</a>
</div>
</ion-content>
</ion-view>
</script>
<script id="info.html" type="text/ng-template">
<ion-view title="Informacje">
<ion-content class="padding">
<div class="card">
<div class="item item-text-wrap">
<img src="img/logo.png" style="width: 100%">
</div>
</div>
</ion-content>
</ion-view>
</script>
</body>
模块应该像这里一样创建它时注入依赖项angular.module('starter', ['ionic'])
但是在使用它时你需要使用angular.module('starter')
,因为模块已经创建。如果您再次执行相同的操作,那么该模块之前注册的组件将被刷新。
就像在您的代码中一样,您需要在定义 controller
和 config
时使用 angular.module('starter')
代码
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
//code here
})
angular.module('starter')//<-- change here
.controller('PopupCtrl', function($scope, $ionicPopup, $timeout) {
//code here
});
angular.module('starter') //<-- change here
.config(function($stateProvider, $urlRouterProvider) {
//code here
})
我有新手问题。
我的应用程序需要一些非常基本的 AngularJS。我使弹出窗口工作,然后添加了 ion-nav-view。这两个元素都起作用,但不是同时起作用。现在 ion-nav-view 工作完美,但是当我改变
body ng-app="starter"
到
body ng-app="starter" ng-controller="PopupCtrl"
应用变成空白网站。
这一定是一些小错误,但我找不到它在哪里。谁能帮我?我的 app.js:
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
StatusBar.styleDefault();
}
});
})
angular.module('starter', ['ionic'])
.controller('PopupCtrl', function($scope, $ionicPopup, $timeout) {
$scope.showAlert = function() {
var alertPopup = $ionicPopup.alert({
title: 'Alert',
template: 'Alert text'
});
};
});
angular.module('starter', ['ionic'])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('list', {
url: '/1',
templateUrl: 'list.html'
})
.state('info', {
url: '/2',
templateUrl: 'info.html'
})
$urlRouterProvider.otherwise("/1");
})
编辑:
index.html 的正文部分:
<body ng-app="starter" ng-controller="PopupCtrl">
<ion-nav-bar class="bar-positive" align-title="center">
</ion-nav-bar>
<ion-nav-view class="slide-left-right"></ion-nav-view>
<script id="list.html" type="text/ng-template">
<ion-view title="title">
<ion-nav-buttons side="right">
<button class="button button-icon icon ion-android-locate" ng-click="showAlert()"></button>
</ion-nav-buttons>
<ion-content>
<div class="list">
<a class="item item-thumbnail-left" href="#">
<img src="cover.jpg">
<h2>Pretty Hate Machine</h2>
<p>Nine Inch Nails</p>
</a>
<a class="item" ui-sref="info">
<p>Żeby uzyskać pomoc, dotknij to pole.</p>
</a>
</div>
</ion-content>
</ion-view>
</script>
<script id="info.html" type="text/ng-template">
<ion-view title="Informacje">
<ion-content class="padding">
<div class="card">
<div class="item item-text-wrap">
<img src="img/logo.png" style="width: 100%">
</div>
</div>
</ion-content>
</ion-view>
</script>
</body>
模块应该像这里一样创建它时注入依赖项angular.module('starter', ['ionic'])
但是在使用它时你需要使用angular.module('starter')
,因为模块已经创建。如果您再次执行相同的操作,那么该模块之前注册的组件将被刷新。
就像在您的代码中一样,您需要在定义 controller
和 config
angular.module('starter')
代码
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
//code here
})
angular.module('starter')//<-- change here
.controller('PopupCtrl', function($scope, $ionicPopup, $timeout) {
//code here
});
angular.module('starter') //<-- change here
.config(function($stateProvider, $urlRouterProvider) {
//code here
})