Javascript AngulajJS中未定义服务功能
我开始学习AngularJS,并尝试从控制器调用服务方法。但当我调用它时,它表示函数未定义 奇怪的是,当我在控制台中打印服务对象时,我可以看到它的功能。但当我试着给它打电话时,它说的是未定义 控制器Javascript AngulajJS中未定义服务功能,javascript,angularjs,Javascript,Angularjs,我开始学习AngularJS,并尝试从控制器调用服务方法。但当我调用它时,它表示函数未定义 奇怪的是,当我在控制台中打印服务对象时,我可以看到它的功能。但当我试着给它打电话时,它说的是未定义 控制器 (function() { angular.module('public') .controller('NewPatientController', NewPatientController); NewPatientController.$inject = ['NewPatientService'
(function() {
angular.module('public')
.controller('NewPatientController', NewPatientController);
NewPatientController.$inject = ['NewPatientService'];
function NewPatientController(NewPatientService) {
var $ctrl = this;
console.log(NewPatientService.register1);
$ctrl.mess = 'hhtg';
$ctrl.success = null;
NewPatientService.regsiter1();
$ctrl.submit = function() {
console.log('Ctrl');
NewPatientService.regsiter1();
}
}
})();
服务
(功能(){
.module('public')
.服务(“NewPatientService”,NewPatientService)
我得到的确切错误是:
NewPatientService.regsiter1 is not a function
有人能指出这里面可能有什么问题吗。这是因为console.log(NewPatientService.register1); 尝试按如下方式删除或更改它
console.log(NewPatientService.register1());
console.log之后的行NewPatientService.regsiter1();
上也有问题
它应该是
NewPatientService.register1();
您所指向的行工作正常,输出为:function(){}您是否仍遇到此问题?存在拼写问题,应该是register1您已创建register1并尝试调用RegSite1。请修复拼写。@Nikhileshv谢谢,愚蠢的错误。
console.log(NewPatientService.register1());