Q: angularjs tree editing and adding with model how to implement correctly? 
I have a tree of li, and a add button with a modal window to add item to it as parent item or as child item.
When I add new item to li as child or as parent item , the tree should expand, but when I add child items to it again , tree collapse instantly.
If I replaced $modelinstance.close() by $modelinstance.dismiss() tree is working perfectly. But I need refresh to see item added - it is not showing the added item instantly.
Below is the code (attribute is a service):
$scope.saveAttribute = function(form) {
   $scope.submitted = true;
   if (form.$valid) {
      if (!$scope.attributeAction) {
         $scope.createAttributeObject();
      }
      //if edit
      if ($scope.attributeAction && $scope.attributeAction === 'Edit') {
         Attributes
            .editAttribute({
               id: $scope.attribute._id
            }, $scope.attribute, function() {
               toastr.success('Attribute saved successfully', 'Success');
               $scope.modalInstance.close();
            }, function(err) {
               $scope.error = err;
            });
      } else {
         //new attribute
         Attributes
            .saveAttribute($scope.attribute, function() {
               //console.log($scope.modalInstance);
               $scope.modalInstance.close($scope);
               toastr.success('Attribute added successfully', 'Success');
               setTimeout(function() {
                  if ($scope.attribute.parentAttribute.id) {
                     //if($scope.modalInstance.close()){
                     console.log($scope.modalInstance.dismiss());
                     angular.element(document.getElementById($scope.attribute.parentAttribute.id)).click();
                  }
               }, 1000);
            }, function(err) {
               $scope.error = err;
            });
      }
   }
};

Attributes service
//service code
angular.module('createWhimsyApp')
   .factory('Attributes', AttributesService);
/**
 * Attribute service
 * @param {Object} $resource Attibute resource
 */
function AttributesService($resource) {
   return $resource('/api/attributes/:id/:controller', {
      id: '@_id'
   }, {
      getAllAttributes: {
         isArray: true,
         method: 'GET'
      },
      saveAttribute: {
         method: 'POST'
      },
      editAttribute: {
         method: 'PUT',
         params: {
            id: 'attribute._id'
         }
      },
      deleteAttribute: {
         method: 'DELETE',
         params: {
            id: 'attrObj._id'
         }
      }
   });
}

