나는 아주 간단한 해결책이 있다고 생각하는 간단한 질문을 가지고 있지만 어떻게 든 그것을 놓치고있다.AngularJS : 지시어와 스코프
내 앱에 간단한 지시문을 설정하고 있습니다. 내 컨트롤러의 범위를 공유하기를 원하기 때문에 범위 속성을 기본값 인 "false"로 설정합니다.
문제는 해당 범위에 액세스 할 수없는 것입니다.
console.dir(scope)
을하고 난 범위 객체 ('페이지') 후 오전 속성을 볼 수 있습니다 내 연결 기능에서
, 나는 할 수 있습니다.
내가 수행하려고 할 경우
console.dir(scope.pages)
하지만, 다시로 정의되어 있습니다.
무엇이 누락 되었습니까?
미리 감사드립니다.
MyDirectives.directive("mdPagination", function(){
return {
templateURL: "/templates/pagination.html",
replace: true,
restrict: 'A',
scope: false, //default
link: function(scope, element, attrs){
console.log('in linking function');
console.dir(scope);
console.dir(element);
console.dir(attrs);
console.dir(scope.pages);
}
}
});
템플릿 :
<nav class="pagination" md-Pagination></nav>
컨트롤러 :
App.controller('MachinesListCtrl', function ($scope, $routeParams, $location, MachineServices, CustomerServices) {
var page = ($routeParams.page ? $routeParams.page : 1);
//if we are getting all machines based on their customer id.
if($routeParams.customerID){
MachineServices.getByCustomerId($routeParams.customerID).then(function (data) {
_.each(data.results, function (machine, index, list) {
CustomerServices.get(machine.customer_id).then(function(data){
machine.CustomerData = data.results;
});
});
$scope.Machines = data.results;
$scope.pages = data.pages;
});
}
//otherwise we just want the regular list of machines.
else{
MachineServices.query(page).then(function (data) {
_.each(data.results, function (machine, index, list) {
CustomerServices.get(machine.customer_id).then(function(data){
machine.CustomerData = data.results;
});
});
$scope.Machines = data.results;
$scope.pages = data.pages;
});
}
});
지시문을 사용할 위치의 템플릿 코드를 표시 할 수 있습니까? 및 scope.pages의 값을 설정 컨트롤러의? –
scope.pages가'undefined'이고 빈 객체 나 배열이 아닌지 확신하십니까? 콘솔에서 pages 속성을보기 위해 범위를 확장하면 무엇이 표시됩니까? 내 대답은 당신이 실제로 빈 객체 나 배열을 보았다고 가정 할 것이므로'scope.pages'를 출력 할 때와 다른 어떤 것을 말해야하는 이유를 볼 수 없다. –