Integrating services with a property editor
Overview
This is step 3 in the Property Editor tutorial. In this part, we will integrate one of the built-in Umbraco Services. For this sample, we will use the notificationsService to show a dialog with a custom view when you click in a textbox. The dialog will appear if the content is longer than 35 characters.
Injecting the service
First up, we need to get access to the service. This is done in the suggestion.controller.js, where we add it as a parameter:
angular.module("umbraco")
.controller("SuggestionPluginController",
// inject Umbraco's assetsService and editor service
function ($scope, notificationsService) { ... }Hooking into Textbox
To hook the service with the textbox, we will use the add method of the notificationsService. This will be used to render our own view by setting the view property. We will also pass an args object which contains the Property Value and a callback function that we are going to call from our notification.
// function to show custom notification
$scope.showNotification = function () {
if ($scope.model.value.length > 35) {
notificationsService.add({
// the path of our custom notification view
view: "/App_Plugins/Suggestions/notification.html",
// arguments object we want to pass to our custom notification
args: {
value: $scope.model.value,
callback: $scope.TrimText
}
});
}
};The callback is used to return data to the editor.
Now that we have access to the editor events, we will trim the text to a length of 35.
Now let's edit the getSuggestion method to call showNotification on clicking Get Suggestions button.
At this point your controller should look like this:
Add the directive in the suggestion.html
suggestion.htmlAdd the JavaScript file in package.manifest
package.manifestCreating custom Notification View and Controller
We will add 2 files to the /App_Plugins/Suggestions/ folder:
notification.htmlnotification.controller.js
In the notification.html, we'll add:
In the notification.controller.js we will add:
Restart the application and either enter a suggestion longer than 35 characters or click on the Get Suggestions button. When you do so and click in the textarea, you will be presented with a notification like this:

The notification object contains the args object that we passed to the view in our suggestion.controller.js. When we click the Yes button in the notification, we use the callback function from the Suggestions controller. This function is executed in the scope of our Suggestions Property Editor.
Wrap up
Over the 3 previous steps, we have:
Created a plugin.
Defined an editor.
Registered the Data Type in Umbraco.
Added a
$scopeobject to pass information from the controller to the view.Added configuration to the Property Editor.
Connected the editor with the Notification Service.
Looked at the notification dialog in action.
Last updated