각도 2에 대한 응용 프로그램을 준비하는 구성 요소로 컨트롤러를 변환하는 데 문제가 있습니다. 그러나 마이그레이션이 잘 진행되지 않는 문제가 있습니다. 라우팅 할 ui-router가 있습니다. 몇 가지 컨트롤러에서 상태를 사용하고 해결할 때 컨트롤러가있는 버전이 작동하지만 구성 요소의 버전이 전혀 작동하지 않아 많은 가이드를 따르고 코드에 도움이되고 있지만 제대로 작동하지 않는 것 같습니다.ui-router가있는 각도 1.5 구성 요소 해결 : 알 수없는 공급자
(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
}
}
});
}
})();
컨트롤러 :
I은 제어기으로 모듈 다음이
상기 코드는 잘 작동하지만 성분로 인한 후(function()
{
'use strict';
angular
.module('app.sample')
.controller('SampleController', SampleController);
/** @ngInject */
function SampleController(SampleData)
{
var vm = this;
vm.helloText = SampleData.data.helloText;
}
})();
그 이렇게 되세요 :
01 23,516,(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 서비스가있는 js를 가지고 있는지 확인할 수 있습니까? – gyc
@gyc 나는 js 파일을 이미 작성했지만 ts로 옮겨 가지는 않았고, 1.5 버전을 사용하여 ts와 함께 두 번째 단계를 준비했다. 컨트롤러 내에서 myService를 사용할 수있다. SampleData는 독립 서비스가 아니며 변수이다. 첫 번째 컨트롤러와 모듈에서 볼 수 있듯이 모듈 내부에서 해결되었습니다. –