2017-12-08 1 views
0

나는 다음 개체와 각도 1.x에서 컨트롤러를 가지고있다. 그러나 이제는 다른 페이지에서 다시 사용해야하는 상황에 처해 있습니다. 적절한 페이지로 복사 할 수는 있지만 리팩터링을 통해 두 컨트롤러가 더 나은 유지 관리를 위해 동일한 목록에서 작동하도록합니다. 저는 'MainApp'모듈에서 상수, 공장 및/또는 지시문을 성공없이 선언하려고했습니다. 내가 뭘 놓치고 있니?수입 각도 JSON 객체

+1

각도 서비스 또는 공장을 사용하여 앱의 다양한 부분에서 데이터를 공유하십시오. – charlietfl

+0

변경하지 않으면 상수로 내보낼 수도 있습니다. 그렇지 않으면 @ charlierfl의 조언을 따라야합니다. –

답변

1

이 문제를 해결하려면 공장을 이용하십시오. 페이지를 변경할 때 데이터는 공장 및 서비스에서 유지 될 수 있습니다.

angular.module('App', [...]) 

.factory('NotificationFactory', function() { 
    var notificationTypes: [ { NotificationType: '*', NotificationTitle: 'All notifications' }, 
       { NotificationType: '0', NotificationLabel: 'System Alert', NotificationTitle: 'System alerts' }, 
       { NotificationType: '1', NotificationLabel: 'Pending Task', NotificationTitle: 'Pending tasks' }, 
       { NotificationType: '2', NotificationLabel: 'Update', NotificationTitle: 'Updates' }, 
       { NotificationType: '3', NotificationLabel: 'Missed Message', NotificationTitle: 'Missed messages' } 
       ]; 

    return notificationTypes; 
})