Copied to clipboard

Flag this post as spam?

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


  • mlu 12 posts 74 karma points
    Feb 21, 2014 @ 11:36
    mlu
    0

    Create An Angular controller in custom section

    Hi everybody. I already build some custom controls in the content section. So now I want to try a custom control in a custom section/application.

    Create a new section is easy. And also add some new action to a node-item. So far I created an edit-Action with the according edit.html

    <div ng-controller="MessageSection.MessageSectionTree.EditController">
    <div class="umb-panel tabbable" ng-transclude="">
            <div class="row-fluid">
    
                <div ng-transclude="">
                    <div class="umb-headline-editor-wrapper span12 ng-scope">
                        <h1 class="ng-binding">Message Section</h1>
                    </div>
                </div>
    
            </div>
        <div class="umb-panel-body umb-scrollable row-fluid ng-scope">
            <div class="umb-pane ng-scope">
                <h3>Message Section</h3>
                <p>This is a single Message - please edit!</p>
            </div>
        </div>
    </div>
    

    According to my understanding, with ng-controller attribute I signalize Angular/Umbraco that I have a .js - controller. So I created in my folder a controller js file: MessageSection.MessageSectionTree.EditController.js

    'use strict';
    (function () {
        //create the controller
        function myTreeEditController($scope, $routeParams) {
            alert("HOWDIE...");
        };
        //register the controller
        angular.module("umbraco").controller('MessageSection.MessageSectionTree.EditController', myTreeEditController);
    })();
    

    But this controller-file isn't loading? Do you have an idea why Angular don't load the controller?

    Thx. For answering.

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Feb 23, 2014 @ 00:21
    David Brendel
    2

    Would suggest you too have a look at package manifest File in the belle API documentation. You need a manifest file that umbraco picks Update and there you specify where the controller file is located

  • Comment author was deleted

    Feb 23, 2014 @ 01:20

    Have you actually included 'MessageSection.MessageSectionTree.EditController.js' on the page?

    i.e. <script src="someFolder/MessageSection.MessageSectionTree.EditController.js"></script>

    Simply referecing the controller from your view is not good enough.

    If you have included this file, but it's not 'working', try inspecting the page and see if you see the file being fetched.

    Are you getting any JS errors in the console?

    The manifest is only for Property Editors.  You'll have to do some of your own housekeeping to add Angularjs stuff to a regular page.

  • mlu 12 posts 74 karma points
    Feb 24, 2014 @ 09:22
    mlu
    0

    @David: This is not an App_Plugin with a manifest. Umbraco itself loads the edit.html by itself. So I would suggest, there must be a naming convention or another mechanisme to force a load of the Javascript.

    @Kevin: Thx for your advice. It is disapointing, there is no other way. So again I need to hardwire the action with the javascript. I expected a more elegant solution - like a naming convention.

  • mlu 12 posts 74 karma points
    Feb 24, 2014 @ 09:51
    mlu
    0

    So I tried to add the javascript in the edit.html

    <script src="../App_Plugins/MessageSection/backoffice/MessageSectionTree/MessageSection.MessageSectionTree.EditController.js"></script>
    

    This will load - but the function will never load in Angular. - I get this error:

    Error: Argument 'MessageSection.MessageSectionTree.EditController' is not a function, got undefined
    at Error (<anonymous>)
    at cb (http://localhost:65204/umbraco/lib/angular/1.1.5/angular.min.js:17:79)
    at xa (http://localhost:65204/umbraco/lib/angular/1.1.5/angular.min.js:17:187)
    at $get (http://localhost:65204/umbraco/lib/angular/1.1.5/angular.min.js:53:310)
    at http://localhost:65204/umbraco/lib/angular/1.1.5/angular.min.js:44:274
    at n (http://localhost:65204/umbraco/lib/angular/1.1.5/angular.min.js:7:74)
    at k (http://localhost:65204/umbraco/lib/angular/1.1.5/angular.min.js:44:139)
    at e (http://localhost:65204/umbraco/lib/angular/1.1.5/angular.min.js:40:139)
    at http://localhost:65204/umbraco/lib/angular/1.1.5/angular.min.js:39:205
    at http://localhost:65204/umbraco/lib/angular/1.1.5/angular.min.js:158:18 
    

    So there must be another solution.

  • Comment author was deleted

    Feb 24, 2014 @ 14:40

    Have you tried validating your JS to make sure you don't have a syntax error?

    You'll get that error if you have any syntax issues.

    IMHO this should work because ng-controller is a contruct of Angularjs and Umbraco doesn't do anything with it.

  • Per Ploug 865 posts 3491 karma points MVP admin
    Feb 24, 2014 @ 14:56
    Per Ploug
    0

    You cant just put in a script tag in your view, the way it works is that all angular-specific scripts are loaded on app start - which it why it works through configuration in the package manifest file:

    http://umbraco.github.io/Belle/#/tutorials/CreatingAPropertyEditor

  • mlu 12 posts 74 karma points
    Feb 24, 2014 @ 14:58
    mlu
    0

    I don't see the line between AngularJS and Umbraco. So it could be my misunderstanding for AngularJS.

    This was the featured code of the example - http://umbraco.github.io/Belle/#/tutorials/Creating-Editors-Trees - but perhaps there is an error. So I tried this code - it worked in a property-editor - which will load through the mentioned package.manifest

    angular.module("umbraco").controller("MessageSection.MessageSectionTree.EditController",
        function ($scope, $http, editorState, poiRessource, assetsService) {
            alert("I am an alert box!");
        });
    

    But still I cannot see there is a request for my controller.

  • David Brendel 792 posts 2970 karma points MVP 3x c-trib
    Feb 24, 2014 @ 15:19
    David Brendel
    104

    All controller files are configured in the package manifest file.

    So if you want to use a controller in the edit.html you have to configure the controller in the manifest file.

    The edit.html is the standard action umbraco calls when clicking on a node in a custom section. Thats why the html can be called. It resides in the right folder.

    But for your controller js file you have to put it in manifest like this:

    {        
        javascript: [
            '~/App_Plugins/MessageSection/backoffice/MessageSectionTree/MessageSection.MessageSectionTree.EditController.js'
        ]
    }
    

    If you have done this umbraco will use the controller.

    Remember to clear cache after you inserted in in your manifest file.

  • Comment author was deleted

    Feb 24, 2014 @ 15:21

    @David.  That's good to know that manifests aren't just for property editors as they seem to imply.

  • mlu 12 posts 74 karma points
    Feb 24, 2014 @ 16:27
    mlu
    0

    @David: Thx a lot.

  • Jason Prothero 422 posts 1243 karma points c-trib
    Mar 09, 2014 @ 22:43
    Jason Prothero
    0

    Per,

    Does that mean I cannot use the AssetsService to load a javascript file that is an AngularJs controller?  Or do I need to pass it a scope or something?

     

    Thanks,

    Jason

  • Krishna 22 posts 52 karma points
    Nov 25, 2015 @ 00:28
    Krishna
    0

    Hi,

    I have a similar problem but declaring the path to the controller in the manifest did not help. I am actually trying angular binding in the dashboard html file.

    Dashboard file:

    <div ng-app="myApp" ng-controller="recallCtrl">
        First Name: <input type="text" ng-model="firstName"><br>
    </div>
    

    Manifest:

    {        
    javascript: [
        '~/App_Plugins/RecallReminder/backoffice/dashboards/recall.controller.js'
    ]
    

    }

    Controller:

    angular.module("umbraco").controller("recallCtrl",
    function ($scope, $routeParams) {
        $scope.firstName = 'First Name Sample'
    });
    

    Area declaration:

    [Application("recallreminder", "RecallReminder", "icon-people", 9)]
    public class RecallReminderSection : IApplication
    {
    }
    

    Any help will be greatly appreciated.

    Thanks, Krishna

  • Rasmus Trumf 78 posts 160 karma points
    Dec 02, 2015 @ 21:46
    Rasmus Trumf
    0

    Krishna you are missing a char ";" at the end of the line in the controller: $scope.firstName = 'First Name Sample';

  • Ranjit J. Vaity 66 posts 109 karma points
    Feb 12, 2018 @ 10:05
    Ranjit J. Vaity
    1

    Hello community,

    Thank you for this post and contributers, was a big help... I had created a Custom Section and Tree to provide different custom tools to our customer. eg Excel uploads, etc

    I spend many hours figuring the reason for js error stating "Argument 'ControllerName' is not a function, got undefined".

    I just happen to fix this issue and realise that package.manifest has to be in the root of the package folder. later all worked well.

    Hope someone might save few hours on such minior but an issue.

    Thanks, Ranjit

Please Sign in or register to post replies

Write your reply to:

Draft