将角度变量传递给Laravel

时间:2015-05-05 15:44:58

标签: angularjs laravel laravel-5

我通过Angular ajax加载数据。如何将返回的结果传递给laravel @include partial?

角:

$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 个答案:

答案 0 :(得分:2)

你真的不能这样做。但您可以在partials.item视图中将结果变量包含为javascript。所以你的HTML看起来像这样:

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

您的partials.item视图会有角度变量而不是laravel变量:

@{{results}}

而不是

{{$results}}

有意义吗?