0

I load data via Angular ajax. How can I pass returned results to laravel @include partial?

Angular:

$scope.findItem = function(itemId) {
    $scope.spinner = true;
    $http.get('item/' + itemId).success(function(results) {
        $scope.spinner = false;
        $scope.results = results[0];
    });
};

html:

<div ng-init="findItem(185)">
    <span ng-show="spinner" class="spinner"></span>
    <div ng-hide="results == undefined">
        @include('partials.item', {{ results }}) // <- I want to pass 'results' here
    </div>
</div>

1 Answer 1

2

You can't really do that. But you can just include the results variable as javascript in your partials.item view. So your HTML would look like this:

<div ng-init="findItem(185)">
    <span ng-show="spinner" class="spinner"></span>
    <div ng-hide="results == undefined">
        @include('partials.item')
    </div>
</div>

And your partials.item view would have angular variables instead of laravel variables:

@{{results}}

Instead of

{{$results}}

Make sense?

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

2 Comments

I'd considered such option, but the only thing I don't know how to go about in such situation is that I load this partial from two different pages, in one I do it with angular, in another with laravel only. So if I change laravel variables to angular, then I will not be able to load it via laravel.
Ok, so in your view, try using this: {{$results or '{{results}}'}}. You may still need to escape, I'm not sure. If so: {{$results or '@{{results}}'}}

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.