vendredi 31 mars 2017

Angular not binding data on html directly

I'm a beginner in Angular (ver 1.6.3) and i ran into this problem :

i have a controller called prof :

    (function ()
{
    'use strict';

    angular
        .module('app.prof', [])
        .controller('ProfController', ProfController);

    /** @ngInject */
    function ProfController($scope, Data)
    {
        var vm = this;

        vm.documents = Data.documents;
        vm.classes = Data.classes;
    }
})();

Here's its associated module :

    (function ()
{
    'use strict';

    angular
        .module('app.prof')
        .config(config);

    /** @ngInject */
    function config($stateProvider, $translatePartialLoaderProvider, msApiProvider)
    {
        // State
        $stateProvider
            .state('app.prof', {
                url    : '/prof',
                views  : {
                    'content@app': {
                        templateUrl: 'app/main/prof/prof.html',
                        controller : 'ProfController as vm'
                    }
                },
                resolve : {
                    Data : function(msApi){
                        return msApi.resolve('data@get');
                    }
                }
            });

        $translatePartialLoaderProvider.addPart('app/main/prof');
        msApiProvider.register('data', ['app/data/prof/prof-data.json']);
    }
})();

And here's the main problem : i have this html :

<div class="document" ng-repeat="document in vm.documents">
                <ms-card template="'app/custom-directives/prof-card/prof-card.html'" ng-model="document"></ms-card>
</div>

it works perfectly fine, the data is correctly binded and all, but when i put the template called directly in the page instead of calling it throught a <ms-card> it doesn't work anymore ! i've tried to put some console.log() a little eveywhere but it always says the data isn't defined; i don't get it. Plus, the ng-repeat always works fine

ps : when i add the html directly i don't forget to put the ng-model="document" but it still doesn't work

This is very confusing for me :/




Aucun commentaire:

Enregistrer un commentaire