1

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

2 Answers 2

1

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

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

        };
Sign up to request clarification or add additional context in comments.

Comments

0

first of all you need to inject ui router

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

2 Comments

ok i did not see it here angular.module('home', []); or do you have other modules too
Update:see on ui the data by using $ctrl.booksList but on controller ctrl.booksList is undefined

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.