0

I am using Laravel 4.2 for an old app. It is mixed with Angular. I need to display a map of locations returned from Laravel.

I am using an Angular directive on a blade template to do this.

I need to pass Laravel values into the directive so they can be used. I saw you can pass an array in this question, but am not sure how to do it with Laravel blade values.

Note: Since blade uses {{ }} for interpolation, I have told Angular to change its interpolation:

$interpolateProvider.startSymbol('[[');
$interpolateProvider.endSymbol(']]');

Laravel blade template: $locations is a blade variable:

<fz-map locations="{{$locations}}"></fz-map>

Directive:

( function( ng, app ) {

    'use strict';

    app.directive( 'fzMap', ['$rootScope', function($rootScope) {
        return {
            restrict: 'AE',
            scope : {
                locations : '='
            },
            link: function(scope, element, attr) {
                console.log('loc', scope.locations);
                scope.Template = '/directive_html/map.html';
            },
            template: "<div ng-include='Template'></div>"
        };
    } ]);
} )( angular, myApp );

Angular error: Unexpected end of expression: [{

2
  • locations : '=' in directive means you are binding to an angular model in parent of the directive. Why can't you make api request for that data? Commented Jan 26, 2016 at 4:38
  • I don't know much about blade -- is it rendered client-side or server-side? As @charlietfl points out, you can only two-way bind to a property in an angular scope. If Blade renders first, you might be able to send the data one-way using '@' or get it into an angular $scope property using ng-init='locations = {{$locations}}'. Just some thoughts...If Angular renders first, then this of course won't work. Commented Jan 26, 2016 at 4:51

0

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.