Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a rootScope variable that will contain category for products, and each category may or may not have children. This is how I assign the rootScope:

$rootScope.categoryList = $http.get('category').then((result) -> result.data) 

This will make request (to Laravel route) to get me arrays of category data, the design of the data looks something like this:

$data = array(
        {category: Category, children: array('child1, child2, child3')},
        {category: Category2, children: null},
        {category: Category3, children: array('anotherchild1, anotherchild2')}
    );

And the way i generate the array is this:

public static function GetCategoryListings($ignore=false) {
    $results = DB::table('category')->where('parent','-')->get();
    $data = array();

    if(!is_null($results)) {
        $i = 0;
        foreach($results as $result) {
            $data[$i]['category'] = $result;
            $child_result = DB::table('category')->where('parent',$result)->get();

            if(!is_null($child_result)) {
                foreach($child_result as $child) {
                    $data[$i]['children'][] = $child;
                }
            }
            else
                $data[$i]['children'] = null;

            $i++;
        }
    }
    return $data;
}

Now, I would like to print my output into the view in Angular, how will I do that? I did something like this:

<li ng-repeat="cat in categoryList">
                {{cat.category}}
            </li>

But it's not working, plus I couldn't output the children. Is there any way around this?

EDIT

Solved my problem by changing to something like this in my view:

<ul>
            <li ng-repeat="cat in categoryList">
                {{cat.category}}
                <ul ng-if="cat.children != null">
                    <li ng-repeat="ch in cat.children">{{ch}}</li>
                </ul>
            </li>
        </ul>
share|improve this question
add comment

1 Answer

There could be a lot of different issues at play here, but this is most likely it.

Angular 1.2 no longer automatically unwraps promises in the templates. You will have to change your syntax to the following:

$http.get('category').then((result) -> $rootScope.categoryList = result.data)

Keep in mind that this might break some other stuff in your app if you relied on categoryList being a promise.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.