私はこの質問が以前に答えられたことを知っていますが、正直なところ私のプログラムの文脈では答えの頭や尾を作ることはできません。ポップアップする「未定義の 『登録』プロパティを読み取ることができません。」私は私のコントローラ内のレジスタの機能を使用しようとする場合を除き、角度アプリのサービスは定義されていません
(function() {
angular
.module('datingApp')
.service('authentication', authentication);
authentication.$inject = ['$window'];
authentication.$inject = ['$http'];
function authentication($window, $http) {
var saveToken = function(token) {
$window.localStorage['token'] = token;
};
var getToken = function() {
return $window.localStorage['token'];
};
var register = function($http, user) {
return $http({
method: 'post',
url: '/users/register',
data: user
})
};
...
return {
saveToken: saveToken,
getToken: getToken,
register: register
}
}
すべて良い:私のサービスは次のようになります。私が書いたダミー関数でさえ、関数のどれも動作しません。
私のコントローラは次のようになります。
angular.module('datingApp').component('signupForm', {
templateUrl: '/public/templates/signup.html',
controller: function signupCtrl($scope, authentication) {
//using an immediate function to generate ages 18-99
$scope.saveData = function(authentication) {
...
authentication.register(x).then(function() { console.log("user saved") }, function() { console.log("failure") });
};
エラー・スタックがこれです:私は間違っ
ypeError: Cannot read property 'register' of undefined
at m.$scope.saveData (signup.form.component.js:72)
at fn (eval at compile (angular.min.js:1), <anonymous>:4:215)
at b (angular.js:15694)
at e (angular.js:25622)
at m.$eval (angular.js:17444)
at m.$apply (angular.js:17544)
at HTMLButtonElement.<anonymous> (angular.js:25627)
at HTMLButtonElement.dispatch (jquery.min.js:3)
at HTMLButtonElement.q.handle (jquery.min.js:3)
何をしているのですか?
をあなたは角をインポートしていますか? – baranskistad
ええ、私のサービス。 –