2

I'm trying to use Angular 1.6 in Laravel blade it raise exception. I have tried this link to solve and many other answer I have tried but non of these worked for me. here is code

<div class="row" ng-app="CalculatorApp" ng-controller="CalculatorController">
    <p>Profit Before {{ var }} </p>
</div>

here is Js co

angular.module('CalculatorApp', []).controller('CalculatorController', 
 function($scope) {
 $scope.var=0;
    });

here is error/exception

use of undefined constant var - assumed 'var'
11
  • Don't use "var" it is a reserved word in javascript, declares a variable. Commented Aug 25, 2017 at 16:35
  • @axel.michel I have another name in my js. just to be on point/error I have changed it. for more understandable Commented Aug 25, 2017 at 16:37
  • Rename the variable name of var and check Commented Aug 25, 2017 at 16:37
  • Change var to any other name and check Commented Aug 25, 2017 at 16:38
  • Already checked? Commented Aug 25, 2017 at 16:38

6 Answers 6

2

Both Laravel and Angular use the double curly brackets per default, this is causing your error:

in Blade you can mark a complete block as string:

@verbatim
<div class="row" ng-app="CalculatorApp" ng-controller="CalculatorController">
    <p>Profit Before {{ var }} </p>
</div>
@endverbatim

Or your angular:

var sampleApp = angular.module('sampleApp', [], function($interpolateProvider) {
    $interpolateProvider.startSymbol('<%');
    $interpolateProvider.endSymbol('%>');
});

In this case all your angular template code has to use something like <%var%>

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

6 Comments

Might be the blade cache? - have a look at: stackoverflow.com/questions/28548694/…, could be helpful.
@MahmoodSanjrani be aware that you just change one of both (either angular or blade, if you change both, you reproduce the error. Or try the blade option "entire block as-is" (see updated answer).
sir I have checked these individually. expect Blade::setContentTags('<%', '%>'); when i use this is show an other error. may be I'm not putting the code in right place. Call to undefined method Illuminate\View\Compilers\BladeCompiler::setContentTags()
sir can you please tell me where should I put this Blade::setContentTags('<%', '%>'); code. may be because of this . I'm facing error.
@MahmoodSanjrani I just checked the issues board at lavarel, seems that the team deleted that option: github.com/laravel/framework/issues/17736 - no way to do this any longer, you'll need to escape the complete block, or using @{{xxx}}
|
1

Use @ to escape blade processsing angular interpolation.

<div class="row" ng-app="CalculatorApp" ng-controller="CalculatorController">
    <p>Profit Before @{{ var }} </p>
</div>

4 Comments

sir I have used it . as I have Link/url/href in my Question. but it only print the value including {{}} .
did u change template tags for angular or laravel? u also need to check if you've bootstrapped angular
sir I'm using bootstrap and I have included Angular external link. I tried to change blade tags and angular tags ,, but none to these are working for me. :(
can you tell me where should I change blade tag. may be I'm putting code in wrong file.\
0

Var is keyword in JavaScript , I hope rename the variable name enough to fix.

1 Comment

Check my comment on question
0

Laravel is also using same template tags so its check for laravel variable. change for angular like this

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

Comments

0
angular.module('CalculatorApp', [$scope]).controller('CalculatorController', function($scope) { $scope.var1=0; });

Check this out.

2 Comments

$scope.var1=0; ? sir I have told you there is not issue of variable name. I have other name in my JS function.
Find another change there inside [$scope]
0

I solved my problem.

1) I changed library.

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>

2) changed code Putted after body start.

    <body>
    var custom = angular.module('CalculatorApp', []);
custom.config(function($interpolateProvider) {
    $interpolateProvider.startSymbol('[[');
    $interpolateProvider.endSymbol(']]');
});
custom.controller('CalculatorController', function($scope) {
    $scope.aa=0;

    }); 

html .

<div class="row" ng-app="CalculatorApp" ng-controller="CalculatorController">
        [[ aa ]]
     </div>

Thanks to everyone who tried to solve this problem. Thank you so much.

Comments

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.