-1
我是angularjs中的新手,并试图学习它。我有一个香草应用程序创建三个不同的js文件他们无法从控制器调用角度服务
loginBoot.js
var LoginBoot = (function(module,$,angular,global){
console.log("Initializing Logging Application");
_appName = document.getElementsByTagName('html').item(0).getAttribute('ng-app');
_app = angular.module(_appName,[]);
$.extend(module,{
appName:_appName,
app:_app
});
return module;
}(LoginBoot ||{},this.jQuery,this.angular,this));
loginService.js
var LoginService = (function(module,$,angular,global){
console.log("Initializing Login Service");
var app = LoginBoot.app;
app.service('GetLoggingCredential'['$scope','$http',function($scope,$http){
this.sayHello = function(){
console.log("Saying Hello");
};
}]);
$.extend(module,{
});
return module;
}(LoginService || {},this.jQuery,this.angular,this));
loginController.js
var LoginController = (function(module,$,angular,global){
console.log("Initializing Login Controller");
var app = LoginBoot.app;
app.controller('loginController',['$scope','$http',function($scope,$http,GetLoggingCredential){
$scope.getUser = function(){
GetLoggingCredential.sayHello();
};
}]);
$.extend(module,{
});
return module;
}(LoginController || {} ,this.jQuery,this.angular,this));
我想通过这个控制器调用一个按钮上的服务。
<button type="button" id="loginSubmit" ng-click="getUser()"/>Click Here</button></div>
但这引发错误
类型错误:无法读取的不确定
财产“的sayHello”我下面组织我的代码的javascript模块模式。任何帮助将真正可观
这样做是抛出一个新的错误中添加
GetLoggingCredential
作为依赖! 错误:[$ injector:unpr]未知的提供者:$ scopeProvider < - $ scope < - GetLoggingCredential –@VaskarRayKarmakar因为没有与服务相关的'$ scope'...请从一些教程开始学习AngularJS。 – Blackhole