Javascript 无法设置属性';登录';添加新页面后的未定义页数?
我正在visual studio中使用ripple运行该应用程序。JS开发者工具在添加新页面后显示以下错误。哪一行导致了错误Javascript 无法设置属性';登录';添加新页面后的未定义页数?,javascript,cordova,azure,ionic-framework,azure-mobile-services,Javascript,Cordova,Azure,Ionic Framework,Azure Mobile Services,我正在visual studio中使用ripple运行该应用程序。JS开发者工具在添加新页面后显示以下错误。哪一行导致了错误 ionic.bundle.js:25642 TypeError: Cannot set property 'login' of undefined at new <anonymous> (http://localhost:4400/js/controllers.js:10:18) at invoke (http://localhost:4400
ionic.bundle.js:25642 TypeError: Cannot set property 'login' of undefined
at new <anonymous> (http://localhost:4400/js/controllers.js:10:18)
at invoke (http://localhost:4400/lib/ionic/js/ionic.bundle.js:17762:17)
at Object.instantiate (http://localhost:4400/lib/ionic/js/ionic.bundle.js:17770:27)
at http://localhost:4400/lib/ionic/js/ionic.bundle.js:22326:28
at Object.self.appendViewElement (http://localhost:4400/lib/ionic/js/ionic.bundle.js:56883:24)
at Object.render (http://localhost:4400/lib/ionic/js/ionic.bundle.js:54995:41)
at Object.init (http://localhost:4400/lib/ionic/js/ionic.bundle.js:54915:20)
at Object.self.render (http://localhost:4400/lib/ionic/js/ionic.bundle.js:56743:14)
at Object.self.register (http://localhost:4400/lib/ionic/js/ionic.bundle.js:56701:10)
at updateView (http://localhost:4400/lib/ionic/js/ionic.bundle.js:62357:23) <ion-nav-view name="side-menu21" class="view-container" nav-view-transition="android">
routers.js
.controller('LoginCtrl', ['client', function (client, $scope, $state) {
$scope.login = function() {
client.login("facebook").then(function succes(data){
console.log('logged in succesfully..')
$state.go('menu.events');
}, function(error){
console.log('login failed.');
//login failed.
});
}
}])
.state('menu.login', {
url: '/login',
views: {
'side-menu21': {
templateUrl: 'templates/login.html',
controller: 'LoginCtrl'
}
}
})
.factory('client', [function () {
var client = new WindowsAzure.MobileServiceClient("https://mysite.azurewebsites.net/");
return client;
}])
;
service.js
.controller('LoginCtrl', ['client', function (client, $scope, $state) {
$scope.login = function() {
client.login("facebook").then(function succes(data){
console.log('logged in succesfully..')
$state.go('menu.events');
}, function(error){
console.log('login failed.');
//login failed.
});
}
}])
.state('menu.login', {
url: '/login',
views: {
'side-menu21': {
templateUrl: 'templates/login.html',
controller: 'LoginCtrl'
}
}
})
.factory('client', [function () {
var client = new WindowsAzure.MobileServiceClient("https://mysite.azurewebsites.net/");
return client;
}])
;
添加文件login.html
<ion-view view-title="Sign in">
<ion-content>
<a class="item button button-block button-assertive" ng-click="login()">
Sign In With Facebook
</a>
</ion-content>
</ion-view>
使用Facebook登录
还添加了meta
和index.html中的引用:
在您编写的控制器定义中
.controller('LoginCtrl',['client',函数(client,$scope,$state){…})
我认为这应该是
.controller('LoginCtrl',['client','$scope','$state',函数(client,$scope,$state){…})
希望这有帮助!在您编写的控制器定义中
.controller('LoginCtrl',['client',函数(client,$scope,$state){…})
我认为这应该是
.controller('LoginCtrl',['client','$scope','$state',函数(client,$scope,$state){…})
希望这有帮助!您的
客户端未定义。可能(如果您可以使用开发人员工具)在页面生命周期中过早尝试初始化它。在触发page onReady事件之前,您无法初始化客户端
我不是ionic专家,但我相信$ionicPlatform.ready()
是您需要关注的东西。您的客户端
没有定义。很可能(如果您可以使用开发人员工具)您试图在页面生命周期的早期对其进行初始化。在触发page onReady事件之前,您无法初始化客户端
我不是离子专家,但我相信$ionicPlatform.ready()
是您需要关注的东西