私はアプリケーションを角度2で準備しているコンポーネントにコントローラを変換することに問題がありますが、問題はマイグレーションがうまくいかないため、いくつかのコントローラでバージョンを使用していますが、コントローラのバージョンは動作していますが、コンポーネントのバージョンはまったく動作しています。私は多くのガイドに従いましたが、コードにはうまくやっているようですが、ui-routerを使用した角度1.5のコンポーネント解決:不明なプロバイダ
Iはコントローラと以下モジュール有する:
(function() {
'use strict';
angular
.module('app.sample', [])
.config(config);
/** @ngInject */
$stateProvider
.state('app.sample', {
url : '/sample',
views : {
'[email protected]': {
templateUrl: 'app/main/sample/sample.html',
controller : 'SampleController as vm'
}
},
resolve: {
SampleData: function (myService) {
return myService.getSample(); // I return a promise here
}
}
});
}
})();
コントローラ:
(function()
{
'use strict';
angular
.module('app.sample')
.controller('SampleController', SampleController);
/** @ngInject */
function SampleController(SampleData)
{
var vm = this;
vm.helloText = SampleData.data.helloText;
}
})();
うまく機能上のコード、BUT 成分そのとしてそれを行った後に次のようになります:
(function() {
'use strict';
angular
.module('app.sample', [])
.config(config);
/** @ngInject */
function config($stateProvider) {
// State
$stateProvider
.state('app.sample', {
url: '/sample',
views: {
'[email protected]': {
template: '<sample></sample>'
}
},
resolve: {
SampleData: function (myService) {
return myService.getSample(); // I return a promise here
}
}
});
}
})();
コンポーネント:今
(function() {
'use strict';
angular
.module('app.sample')
.component('sample', {
templateUrl: 'app/main/sample/sample.html',
bindings: {
},
controller: Sample
});
/** @ngInject */
function Sample(SampleData) {
var $ctrl = this;
$ctrl.helloText = SampleData.data.helloText;
}
})();
しかし、その作業を、私に次のエラー与えない:
"dependencies": {
"angular": "1.5.7",
"angular-animate": "1.5.7",
"angular-aria": "1.5.7",
"angular-cookies": "1.5.7",
"angular-material": "1.1.0-rc.5",
"angular-messages": "1.5.7",
"angular-resource": "1.5.7",
"angular-sanitize": "1.5.7",
"angular-ui-router": "1.0.0-beta.1",
"jquery": "2.2.4",
"mobile-detect": "1.3.2",
"moment": "2.13.0"
}
:
bower.json内部
Error: [$injector:unpr] Unknown provider: SampleDataProvider <- SampleData
http://errors.angularjs.org/1.5.7/$injector/unpr?p0=SampleDataProvider%20%3C-%20SampleData
at angular.js:68
at angular.js:4502
at Object.getService [as get] (angular.js:4655)
at angular.js:4507
at getService (angular.js:4655)
at injectionArgs (angular.js:4679)
at Object.invoke (angular.js:4701)
at $controllerInit (angular.js:10234)
at nodeLinkFn (angular.js:9147)
at angular.js:9553
私の依存関係を
何が問題なのか、何が分からないの?代わりに、上記のように与えるの
index.htmlの中にサービスSampleDataが含まれていることを確認できますか? – gyc
@gyc私は既にjsファイルを書いていますが、まだtsに移動していませんが、角度1.5を使ってts後で第2段階に準備しています。コントローラ内でmyServiceを使用できます.SampleDataは独立サービスサービスではなく、あなたが最初のコントローラとモジュールで動作しているのと同じように、内部のモジュールを解決しました。 –