의 모든 컨트롤러 의존성 해결 : I가 다른 제어기 (하위 제어기)를 사용하여 템플릿 HTML에서를 주입은이 같은 UI 라우터 상태를 UI 라우터
$stateProvider.state('parent', {
templateUrl: 'tpl/a.html',
resolve: {
resA: function() {
return { 'value': 'A' };
}
},
controller: function($scope, resA) {
$scope.resA = resA.value;
}
});
한다. 이 하위 컨트롤러는 ui 라우터 상태의 종속성을 해결해야합니다. 그러나 자식 컨트롤러에는 주입되지 않습니다.
TPL/a.html
<h1>Hello</h1>
<div ng-controller="ChildCtrl">
</div>
ChildCtrl
var app = angular.module('app', []);
app.controller('ChildCtrl', function($scope, resA) {
// some codes
});
나는 ChildCtrl에, 그 RESA의 unkonwn을 오류를 얻었다. ChildCtrl에 resA를 삽입하는 방법?
//it would be available in child controller in `$scope.a`
$stateProvider.state('parent', {
templateUrl: 'tpl/a.html',
resolve: {
resA: function() {
return { 'value': 'A' };
}
},
controller: function($scope, resA) {
$scope.resA = resA.value;
}
})
.state('parent.child', {
templateUrl: 'tpl/child.html',
controller: function($scope) {
console.log($scope.resA) //'{value: "A"}'
}
});
2) 하위 경로에 대한 컨트롤러로 아이 컨트롤러를 넣어
1) 부모 컨트롤러의 $ 범위의 값을 넣어뿐만 아니라이 RESA를 해결 :
답변 해 주셔서 감사합니다. 나는 2 단계에서 이해하지 못한다. 몇 가지 코드를 추가 할 수 있습니까? – windupurnomo
@windupurnomo, 답을 확인, 예를 넣었습니다 – BotanMan