Hi there!
I’ve been trying for some time now to get my custom plugin working, but I’m stuck. It seems like none of my Angular controllers from init/resources.controller.js
are being triggered when I try to navigate to list/create/edit views in my custom section.
Here’s my folder structure:
/App_Plugins/
└── Resources/
├── package.manifest
├── init/
│ ├── routes.js
│ └── resources.controller.js
└── views/
├── resource-shell.html
├── resource-list.html
├── resource-create.html
└── resource-edit.html
package.manifest
{
"sections": [
{
"alias": "resources",
"name": "Resources",
"icon": "icon-documents",
"showOnTablet": true
}
],
"dashboards": [
{
"alias": "resourceDashboard",
"view": "/App_Plugins/Resources/views/resource-shell.html",
"sections": [ "resources" ],
"weight": 0
}
],
"trees": [
{
"alias": "resourcesTree",
"section": "resources",
"treeAlias": "resourcesTree",
"name": "Resources"
}
],
"javascript": [
"~/App_Plugins/Resources/init/routes.js",
"~/App_Plugins/Resources/init/resources.controller.js"
],
"css": []
}
In resource-shell.html
, I’ve added an <ng-view>
element to handle routing between views.
routes.js
angular.module("umbraco").config(function ($routeProvider) {
$routeProvider
.when("/resources/create", {
templateUrl: "/App_Plugins/Resources/views/resource-create.html",
controller: "Resources.CreateController"
})
.when("/resources/edit/:udi", {
templateUrl: "/App_Plugins/Resources/views/resource-edit.html",
controller: "Resources.EditController"
})
.when("/resources", {
templateUrl: "/App_Plugins/Resources/views/resource-list.html",
controller: "Resources.ListController"
})
.otherwise({
redirectTo: "/resources"
});
console.log("🧠 routes.js loaded");
});
My controllers are not being hit
resources.controller.js
angular.module("umbraco").controller("Resources.ListController", function ($scope, $http, navigationService) {
console.log("💥 ListController loaded", $routeParams); <--- This never get call'd
$scope.children = [];
$http.get("/umbraco/backoffice/Resources/ResourcesApi/Children")
.then(res => $scope.children = res.data);
});
angular.module("umbraco").controller("Resources.CreateController", function ($scope, $http, $routeParams, notificationsService, navigationService) {
console.log("💥 Resources.CreateController loaded"); <-- This never get call'd
$scope.parentUdi = $routeParams.parentUdi || null;
$scope.model = {
title: "",
type: "textResource",
dataJson: "{}",
parentUdi: $scope.parentUdi
};
$scope.save = function () {
$http.post("/umbraco/backoffice/Resources/ResourcesApi/Create", $scope.model)
.then(function (res) {
notificationsService.success("Resource is added", "Your resource is saved");
// Sync tree for at vise ny ressource
navigationService.syncTree({
tree: "resourcesTree",
path: ["-1"],
forceReload: true
});
})
.catch(function (err) {
console.error("❌ Create failed", err);
notificationsService.error("error at creation", "insue the fields are correct and try again");
});
};
});
angular.module("umbraco").controller("Resources.EditController", function ($scope, $http, $routeParams, notificationsService, navigationService) {
console.log("🛠 EditController loaded for UDI:", $routeParams.udi); <-- This is never get call'd
$scope.udi = $routeParams.udi;
$scope.model = null;
$scope.loading = true;
// Hent eksisterende ressource
$http.get("/umbraco/backoffice/Resources/ResourcesApi/GetByUdi?udi=" + encodeURIComponent($scope.udi))
.then(function (res) {
$scope.model = res.data;
$scope.loading = false;
})
.catch(function (err) {
notificationsService.error("could get resource", "error reading data");
$scope.loading = false;
});
// Gem ændringer
$scope.save = function () {
$http.post("/umbraco/backoffice/Resources/ResourcesApi/Update", $scope.model)
.then(function () {
notificationsService.success("Saved", "Resource er updated");
navigationService.syncTree({ tree: "resourcesTree", path: ["-1"], forceReload: true });
})
.catch(function () {
notificationsService.error("Fejl", "Changes could not be saved");
});
};
});
console.log("✅ controller.js is loaded!");
What am I missing?
I suspect it’s something simple in how I’m registering the controllers or routes. Both routes.js
and resources.controller.js
exist and seem correct.
Copilot and I are just going in circles at this point — any help or fresh eyes would be much appreciated!
Thanks in advance