[英]I am trying to connect my Azure backend with my ionic angular front end
The table is called sport and I am trying to show the list from the column sport in a drop down list. 该表名为sport,我试图在下拉列表中显示列运动列表。 The error I am getting is Error: [$injector:unpr] Unknown provider: sportServiceProvider <- sportService <- sportCtrl and I cannot see where the mistake is, can anyone help?
我得到的错误是错误:[$ injector:unpr]未知的提供者:sportServiceProvider < - sportService < - sportCtrl我无法看到错误在哪里,任何人都可以帮忙吗?
<ion-view view-title="Choose Your Team">
<ion-content ng-controller="sportCtrl as vm" >
<label class="item item-input item-select item-positive">
<div class="input-label">
Sport
</div>
<select>
<option>
{{vm.sport}}
</option>
</select>
</label>
</div>
The service to get the sport is sport.js 获得这项运动的服务是sport.js
(function () {
'use strict';
sportService.$inject = ['$http'];
angular
.module('starter',[azure-mobile-service-module])
.factory('sportService', sportService);
function sportService($http) {
var service = {
getData: getData
};
return service;
function getData() {
Azureservice.query('sport', {})
.then (function(sport)
{
vm.sport = sport;
})}
}
})();
angular.module('starter').constant('AzureMobileServiceClient', {
API_URL: "https://",
API_KEY: "",
});
and the controller is: 控制器是:
(function () {
'use strict';
sportCtrl.$inject = ['sportService'];
angular
.module('starter')
.controller('sportCtrl', sportCtrl);
function sportCtrl(sportService) {
var vm = this;
activate();
function activate() { }
vm.sportname = sportService.getData();
}
})();
It seems that you have initialized repeated angular module named starter
, in your sport.js
and controller.js
scripts. 您似乎已经在
sport.js
和controller.js
脚本中初始化了名为starter
重复角度模块。 In the controller.js
script, you have created a new angular application instance which do not have a sportService
injected. 在
controller.js
脚本中,您创建了一个sportService
注入sportService
的新角度应用程序实例。
You can define a global variable to the angular instance in sport.js
, eg 您可以为
sport.js
的角度实例定义全局变量,例如
app = angular
.module('starter',...)
And use this global variable instead of angular.module('starter')
, eg 并使用此全局变量而不是
angular.module('starter')
,例如
app.controller('sportCtrl', sportCtrl);
Otherwise, you can define a new angular module for your controller and inject in the main angular module. 否则,您可以为控制器定义新的角度模块,并注入主角度模块。 EG
例如
In your controller.js
: 在你的
controller.js
:
angular
.module('starter.ctrl')
.controller('sportCtrl', sportCtrl);
And in your sport.js
: 在你的
sport.js
:
angular
.module('starter',[azure-mobile-service-module,'starter.ctrl'])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.