formly-js / angular-formly

JavaScript powered forms for AngularJS
http://docs.angular-formly.com
MIT License
2.22k stars 405 forks source link

I'm trying to add input-types (templates) at run-time #524

Closed iJungleboy closed 8 years ago

iJungleboy commented 8 years ago

I'm doing this because when the first scripts load, it's not clear yet which fields will be needed. That is only discovered once the first JSONs arrive containing the content-type-definition and the fields-list. Then I want to load the custom UIs (some are heavy, like WYSIWYGs or Google-map-pickers).

Basically I just load more scripts containing more definitions like:

angular.module("eavFieldTemplates")
    .config(function(formlyConfigProvider, defaultFieldWrappers) {

        formlyConfigProvider.setType({
            name: "custom-gps",
            templateUrl: "fields/custom-gps/custom-gps.html",
            wrapper: defaultFieldWrappers,
            controller: "FieldTemplate-CustomGpsController"
        });
    })
    .controller("FieldTemplate-CustomGpsController", function ($scope, $filter, $modal, appId, debugState, eavAdminDialogs) {

    });

but so far have not been successful. I assume formly doesn't re-init the possible templates-list or something - or most likely I just didn't find the right documentation. What do you think?

Thanks a bunch - especially for the entire formly - you rock :)!

kentcdodds commented 8 years ago

This should totally work. Could you follow the instructions here to give a reproducible example? http://help.angular-formly.com

iJungleboy commented 8 years ago

I'll try...thanks...

kentcdodds commented 8 years ago

Hi @iJungleboy, this is totally possible with angular-formly, so I'm going to assume that you just need help getting things set up. Because of this, please follow the instructions at http://help.angular-formly.com and I'll go ahead and close this issue (github issues on this repo are reserved for bug reports and feature requests). See you on chat!

iJungleboy commented 8 years ago

ok, thanks!

iJungleboy commented 8 years ago

@kentcdodds thanks, I got it to work. Core problem was late dependency injection, which I could solve using ocLazyLoad.