Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Marco Teodoro 54 posts 127 karma points
    21 days ago
    Marco Teodoro
    0

    how to communicate between angular controllers

    Hi community.

    I've a few custom sections with editors and dialogs i thought they were working fine but yesterday i found a problem with the way i'm codding the dialogs and the editors.

    Atm i've an editor view, one js controller and inside this js controller i've a few tabs with listviews. First question is how would you make the listview load only when the tab is visible or selected instead of loading all the list views on the controller constructor?

    Second question is how to use a custom controller for the dialog and communicate back to the main controller to refresh the changes we did on the dialog controller. My problem now is that i'm using the same controller on the dialog and on the editor and this is making the controller to be reinitialized and load on the information from server when i don't need it, but i still want to refresh from database when i close the dialog.

    (function () {
    "use strict";
    
            //controller 
            function editorController($scope, $routeParams, $http, myResource {   
            function onInit() {
                $scope.refreshListView();
              }
    
             $scope.refreshListView= function () {
                 $scope.listviewData = myResource.getListViewData();
              }
                     $scope.openOverlay= function () {
    
                    //this will open the overlay that is created inside the editor html file
               $scope.overlay = {
                     model: model,
                     view: "../App_Plugins/../Dialog.html",
                     title: "TITLE",
                     show: true,
                     ubmitButtonLabel: "Save",
                     submit: function (model) {
                        // myResource.Post(model)
                        //$scope.refreshListView()
                      }
                 }
    
           onInit();
            }         
    angular.module("umbraco").controller("MySection.editorController", editorController); 
            })();
    

    This is a sample of what i have. So the dialog and the editor both shares the same controller. I saw something about using the dialog service. Does any one have a sample that i can look at?

    Basically what i'm trying to achieve is this:

    1. Editor :1 html view, with the tabs and list views (if possible tell me how to load the list views only when tab is visible, or load on tab click) and a the corresponding js controller. Is it possible to have 1 controller for each tab? Is this the proper way to do this?
    2. edit/create grid item on a dialog and leave all this logic outside the main controller. When complete, call a function in the editor controller to refresh the list view.

    I thought i could make a window.location, or window reload but that's a kind of hacks i'm trying to avoid. :)

    i hope this is a common issue and someone else already has the correct solution for this.

    Cheers, Marco

Please Sign in or register to post replies

Write your reply to:

Draft