index.js
angular.module("travel")
.controller('LoginCtrl', function($scope, AuthService, $ionicPopup, $state) {
$scope.user = {
name: '',
password: ''
};
$scope.login = function() {
AuthService.login($scope.user).then(function(msg) {
$state.go('inside');
}, function(errMsg) {
var alertPopup = $ionicPopup.alert({
title: 'Login failed!',
template: errMsg
});
});
};
})
.controller('RegisterCtrl', function($scope, AuthService, $ionicPopup, $state) {
$scope.user = {
name: '',
password: ''
};
$scope.signup = function() {
AuthService.register($scope.user).then(function(msg) {
$state.go('outside.login');
var alertPopup = $ionicPopup.alert({
title: 'Register success!',
template: msg
});
}, function(errMsg) {
var alertPopup = $ionicPopup.alert({
title: 'Register failed!',
template: errMsg
});
});
};
})
.controller('InsideCtrl', function($scope, AuthService, API_ENDPOINT, $http, $state) {
$scope.destroySession = function() {
AuthService.logout();
};
$scope.getInfo = function() {
$http.get(API_ENDPOINT.url + '/memberinfo').then(function(result) {
$scope.memberinfo = result.data.msg;
});
};
$scope.logout = function() {
AuthService.logout();
$state.go('outside.login');
};
})
.controller('AppCtrl', function($scope, $state, $ionicPopup, AuthService, AUTH_EVENTS) {
$scope.$on(AUTH_EVENTS.notAuthenticated, function(event) {
AuthService.logout();
$state.go('outside.login');
var alertPopup = $ionicPopup.alert({
title: 'Session Lost!',
template: 'Sorry, You have to login again.'
});
});
});
app.js
angular.module("travel" ,['ionic'])
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('outside', {
url: '/outside',
abstract: true,
templateUrl: 'templates/outside.html'
})
的index.html
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="angular.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="js/services.js"></script>
<script src="js/constants.js"></script>
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>FinalYearProject</title>
</head>
<body ng-app="travel" ng-controller="AppCtrl">
<ui-view></ui-view>
</body>
</html>
我通过添加角度的cdn得到角度js未定义错误现在我得到的错误就像找不到'travel'模块 Anugular js代码也更新为索引js 请帮助我解决此错误
答案 0 :(得分:1)
HTML:
<!DOCTYPE html>
<html>
<head>
<script src="../bower_components/angular/angular.min.js"></script>
<script src="../bower_components/angular-ui-router/release/angular-ui-router.min.js"></script>
// Some ionic reference
<script src="app.js"></script>
<script src="index.js"></script>
<title>FinalYearProject</title>
</head>
<body ng-app="travel" ng-controller="AppCtrl">
<div ui-view>
{{1+1}}
</div>
</body>
</html>
app.js
(function () {
'use strict';
var app = angular.module('travel', ['ui.router','ionic']);
//Configuration for Angular UI routing.
app.config([
'$stateProvider', '$urlRouterProvider',
function ($stateProvider, $urlRouterProvider, $locationProvider) {
$stateProvider
.state('outside', {
url: '/outside',
template: '<h1>My Contacts</h1>'
});
$urlRouterProvider.otherwise('/outside');
}
]);
})();
答案 1 :(得分:0)
可能会导致 angular js not defined error ,因为可能无法访问cdn。因此,不会创建角度变量,当您在app.js中到达行angular.module("travel" ,['ionic'])
时,找不到 angular 。
另一方面,您的&#34; travel&#34; 模块已正确定义。