Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
titlePushing data into the dialog with a custom scope
$scope.helperFunction = function(x) { return "something" };
 
confirmDeleteRelationship = function(rel) {
    var dialogScope = $scope.$new();  // Doing $scope.$new(true) instead gives an isolated scope (with no access to helperFunction)
    angular.extend(dialogScope, {
        relationship: rel
    });
    ngDialog({
        scope: dialogScope,
        template: "..."
    })
    .finally(function() {
        dialogScope.$destroy(); // I assume you need to do this to avoid leaking resources
    });
}

// in the view you can do something like this:
//   {{ relationship.personA }} is related
//   via {{ relationship.relationshipType.display }}
//   to {{ relationship.personB }}
//
// and you can also access
//   {{ helperFunction(relationship) }}

 

Using a controller

Pro: this is the best (I hadn't tried it yet when I wrote all the above)

It works something like this (I haven't tried this yet.)actually tested this code)

Code Block
confirmDeleteRelationship = function(rel) {
    ngDialog({
        controller: ["$scope", function($scope) { // you can also inject a service with helper functions
			$scope.relationship = rel;
		}],
        template: "..."
    });
}
 
// in the view you can do something like this:
//   {{ relationship.personA }} is related
//   via {{ relationship.relationshipType.display }}
//   to {{ relationship.personB }}