Yossi
Yossi

Reputation: 347

Using angular 1.6.1 and angular-ui-router 0.3.2 make resolve issues

This is my module:

> (function () {
>     'use strict';
> 
>     // CREATE module
>     angular
>         .module('home', []);
>     // Module's CONFIG
>     angular
>         .module('home')
>         .config(function ($stateProvider) {
>             console.log("angular.module('home').config()");
>             $stateProvider
>                 .state('search', {
>                     url: '/search',
>                     template: '<search books-list="$resolve.booksList"></search>',
>                     resolve: {
>                         booksList: function (dataService) {
>                             return dataService.get('app/data/books.json').then(function succsess(data) {
>                                 return data;
>                             }, function error(error) {
>                                 return error;
>                             });;
>                         }
>                     }
>                 });
>             /* Add New States Above */
>         }
> 
>         );
> 
> })();

Here is my component:

(function () {
    'use strict';

/* JAVASCRIPT */

/**
 * Search Object/function
 */

console.log("Search component load");

/** @ngInject **/
function searchController($state) {
    /***************** PRIVATE *******************/

    console.log("searchController load");
    var ctrl = this;
    ctrl.x = ctrl.booksList;

    /**
    * @name: .
    * @description: .
    **/

    /****************** PUBLIC *******************/
}
/* ANGULAR */
angular
    .module('home')
    .component('search', {
        templateUrl: 'app/home/components/search/search.component.html',
        controller: searchController,
        bindings: {
            booksList: '<'
        }
    });

})();

I cant see the data that return from resolve function on my module (equal to undefined) Angular version 1.6.1 and ui router 0.3.2 Also try to inject the booksList to component controller but get unknown provider error

Upvotes: 1

Views: 826

Answers (2)

Yossi
Yossi

Reputation: 347

Use this.$onInit to init my bookList like that:

this.$onInit = function _init() {
            ctrl.booksList = ctrl.books.data;

        };

Upvotes: 1

devadrion
devadrion

Reputation: 216

first of all you need to inject ui router

angular.module('yourmodule', [
    'ui.router'
  ]);

Upvotes: 0

Related Questions