Copied to clipboard

Flag this post as spam?

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


  • crono 58 posts 129 karma points
    Jul 10, 2014 @ 15:44
    crono
    0

    AngularJS dependencies for backend

    Hi,

    I'm trying to add the ngGrid to a custom umbraco DataType, but I can't quite figure out why it's not working.

    I tried adding ['ngGrid'] to angular.module("umbraco"), but gives me: No module: ngGrid

    I sniffed around in the umbraco folders and found the loader.js and app.js - but adding ngGrid file-references to them did nothing (adding to app.js gives me the same error as when I add ['ngGrid'] in my controller).

    It seems obvious to me that it won't find the module, since it hasn't been loaded anywhere.

    Someone suggested using the assetsService with; app.requires.push('ngGrid'); - which doesn't generate any errors, but doesn't render the grid below, either;

     <div class="gridStyle" ng-grid="gridOptions"></div>

    I've tried adding the javascript reference in the package.manifest as well, but that fails silently (the plugin loads, but only shows the label, which is disabled in the manifest config).

    I know there must be a way to load these dependencies, but I'm out of ideas =/

    Any help or guidance is greatly appriciated :)

  • Dave N 13 posts 34 karma points
    Jul 11, 2014 @ 05:48
    Dave N
    0

    You can load javascript as part of a property editor, but it seems you have to have a .html file - whether it's used or not.

    You're package.conf should look like

    {    
    propertyEditors: [
            {
                /*unique alias*/
                alias: "My.NewProperty",
                /*name*/
                name: "My New Property",
                /*html file (view) to render the editor*/
                editor: {
                    view: "~/App_Plugins/NewProperty/newProperty.html",
                }
            }
        ]
        ,
        //array of files we want to inject into the application on app_start.
        //In this case a controller (necessary) and stylesheet (optional)
        javascript: [
            '~/App_Plugins/NewProperty/MyNewController.js'
        ]
    }

    and your ~/App_Plugins/NewProperty/newProperty.html can be anything - I've put just a div in it

  • crono 58 posts 129 karma points
    Jul 11, 2014 @ 09:26
    crono
    0

    Thanks for the reply Dave,

    From the docs, it seems like it would be the correct approach - but it doesn't work for me =/

    My manifest already looks like that - and I did try including the .js for ngGrid in the javascript section, but didn't work (only shows the label for 'Form Records', nothing else - and it shouldn't even be showing the label in the first place - no errors though.) Chrome console outputs: 'Umbraco.MainController' is not a function, got undefined if I add more than one script reference to the list.

    {
        propertyEditors: [
            {
                    alias: "formRecords",
                    name: "Form Records",       
                    editor: {
                    view: "~/App_Plugins/Form Records/formrecords.html",
            hideLabel: true
                    }
            }
        ]
        ,
        javascript: [
    
            '~/App_Plugins/Form Records/formrecords.controller.js'
        ]
    }

    I already made a 'list view' in my html, and it works - but I would like to use ngGrid (or similar) to display the data instead.

     

  • Tom Van Rompaey 38 posts 136 karma points
    Jul 11, 2014 @ 15:25
    Tom Van Rompaey
    0

    You need to add this line before your angular controller: app.requires.push('ngGrid');

    http://our.umbraco.org/forum/umbraco-7/developing-umbraco-7-packages/47905-Including-an-angular-module

     

    And there's also an open issue regarding injecting angular modules:

    http://issues.umbraco.org/issue/U4-2769

     

    Hope this helps! 

  • crono 58 posts 129 karma points
    Jul 11, 2014 @ 17:47
    crono
    0

    Hi tvanro - thanks for chiming in :)

    I tried what you suggested, before posting this topic, and couldn't get it to work. I could see the module was loaded into the browser, but the html <div ng-grid="data"> didn't render anything.

    I ended up rolling my own, but looking forward to a possible fix in 7.2..

    Thanks for the heads-up on the open issue.

  • Alain 73 posts 520 karma points c-trib
    Jan 04, 2015 @ 13:22
    Alain
    1

    Lately I have been working on a package that uses ng-grid.

    Here is a full example.

    package.manifest

    {   
        propertyEditors: [      
            {
                alias: "MyPropertyEditor",
                name: "My property editor",
                editor: {
                    view: "~/App_Plugins/MyPropertyEditor/mypropertyeditor.html"
                }
            }
        ],
        javascript: [
            '~/App_Plugins/MyPropertyEditor/mypropertyeditor.controller.js', 
            '~/App_Plugins/MyPropertyEditor/ng-grid.min.js'
        ],
        css: [
            '~/App_Plugins/MyPropertyEditor/mypropertyeditor.css',
            '~/App_Plugins/MyPropertyEditor/ng-grid.min.css'
        ]
    }
    

    mypropertyeditor.html

    <div ng-controller="MyPropertyEditorController">
        <div class="grid" ng-grid="gridOptions">
        </div>
    </div>
    

    mypropertyeditor.controller.js

    'use strict';
    (function () {
    
        // Controller
        function MyPropertyEditorController($scope) {
    
            $scope.myData = [{ name: "Moroni", age: 50 },
                            { name: "Tiancum", age: 43 },
                            { name: "Jacob", age: 27 },
                            { name: "Nephi", age: 29 },
                            { name: "Enos", age: 34 }];
    
            $scope.gridOptions = { data: 'myData' };
    
        };
    
        //Adding ngGrid
        app.requires.push('ngGrid')
    
        // Register the controller
        angular.module("umbraco").controller('MyPropertyEditorController', MyPropertyEditorController);
    
    })();
    

    mypropertyeditor.css

    .grid {
        width: 100%;
        height: 250px;
        border: 1px solid rgb(210,210,210);
    }
    

    enter image description here

    Hope that can help someone!

Please Sign in or register to post replies

Write your reply to:

Draft