ionic - [ng:areq] Argument 'LoginCtrl' is not a function, got undefined
本文介绍了ionic - [ng:areq] Argument 'LoginCtrl' is not a function, got undefined的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
用ionic开发app时控制台一直报这个错,贴上我的代码
index.html
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<link href="lib/ionic/css/ionic.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="cordova.js"></script>
<script src="js/app.js"></script>
<script src="js/controllers.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="js/jquery.base64.min.js"></script>
</head>
<body ng-app="starter">
<ion-nav-bar class="bar-positive">
</ion-nav-bar>
<ion-nav-view>
</ion-nav-view>
</body>
</html>
app.js
angular.module('starter', ['ionic'])
.run(function($ionicPlatform) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
cordova.plugins.Keyboard.disableScroll(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
});
})
.config(['$stateProvider','$urlRouterProvider',function($stateProvider,$urlRouterProvider) {
$stateProvider
.state("tabs",{
url:"/tab",
abstract: true,
templateUrl: "templates/tabs.html",
})
.state('tabs.home', {
url: "/home",
views: {
'home-tab': {
templateUrl: "templates/home.html"
}
}
})
.state('tabs.login',{
url:"/login",
views:{
"login-tab":{
templateUrl: "templates/login.html",
controller:"LoginCtrl"
}
}
})
.state('tabs.mentions',{
url:"/mentions",
views:{
"mentions-tab":{
templateUrl: "templates/mentions.html"
}
}
})
.state('tabs.post',{
url:"/post",
views:{
"post-tab":{
templateUrl: "templates/post.html"
}
}
})
.state('tabs.browse',{
url:"/browse",
views:{
"browse-tab":{
templateUrl: "templates/browse.html"
}
}
})
.state('tabs.search',{
url:"/search",
views:{
"search-tab":{
templateUrl: "templates/search.html"
}
}
});
$urlRouterProvider.otherwise("tab/home");
}]);
controllers.js
angular.module("starter.controllers",[])
.controller("LoginCtrl",['$scope','$http'],function ($scope,$http) {
$scope.login=function() {
alert(999);
};
});
login.html
<ion-view view-title="Login">
<ion-content>
<div class="list list-inset">
<label class="item item-input">
<input type="text" placeholder="请输入账号">
</label>
<label class="item item-input">
<input type="password" placeholder="请输入密码">
</label>
</div>
<div class="padding">
<button class="button button-block button-positive" ng-click="login()">登录</button>
</div>
</ion-content>
</ion-view>
解决方案
angular.module('starter', ['ionic','starter.controllers']);
你的模块依赖没加
angular.module("starter.controllers",[])
.controller("LoginCtrl",['$scope','$http',function ($scope,$http) {
$scope.login=function() {
alert(999);
};
}]);
这篇关于ionic - [ng:areq] Argument 'LoginCtrl' is not a function, got undefined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文