嗨im非常新的Angulay js离子发展。我点击按钮时尝试基本导航。但是当我点击Firebug控制台中的按钮时,我收到此错误。我想在点击后导航到搜索页面
Error : $state isnot defined
这是我的App.js代码
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('signin', {
url: "/sign-in",
templateUrl: "templates/sign-in.html",
controller: 'AppCtrl'
})
.state('app', {
url: "/app",
abstract: true,
templateUrl: "templates/menu.html",
controller: 'AppCtrl'
})
.state('app.search', {
url: "/search",
views: {
'menuContent': {
templateUrl: "templates/search.html"
}
}
})
// if none of the above states are matched, use this as the fallback
$urlRouterProvider.otherwise('/sign-in');
});
这是我的控制器
angular.module('starter.controllers', [])
.controller('AppCtrl', function($scope, $ionicPopup, $timeout, $ionicModal) {
$scope.signIn = function(user) {
//console.log('Sign-In', user);
$state.go('app.search');
};
})
我的HTML按钮是
<button class="button button-block button-positive" id="login-btn" ng-click="signIn(user)" type="submit">Log in</button>
答案 0 :(得分:4)
您还应养成正确注入依赖项的习惯。它看起来应该是这样的(包括$ state注入):
.controller('AppCtrl',['$scope', '$ionicPopup', '$timeout', '$ionicModal', '$state', function($scope, $ionicPopup, $timeout, $ionicModal, $state) {
$scope.signIn = function(user) {
//console.log('Sign-In', user);
$state.go('app.search');
};
}])
只需确保引号中的注入顺序与以下函数中参数的顺序相同。