This question already has an answer here:
I'm new in angular Js.
Using angular variable in blade file, I'm getting the following error:
Use of undefined constant count - assumed 'count' (View: C:\xampp\htdocs\angularjsLaravelesources\views\testing.blade.php)
My code,
app.js
var app = angular.module('employeeRecords', []);
(function (app) {
"use strict";
app.controller("EmployeesController", function ($scope, $http) {
$http({
method: 'GET',
url: '/employees'
}).then(function (employees){
$scope.employees = employees['data'];
},function (error){
console.log(error);
});
$scope.remaining = function () {
var count = 0;
angular.forEach($scope.employees, function (employee) {
count += employee.done ? 0 : 1;
});
}
});
})(app);
blade.php
<div id="employee" ng-controller="EmployeesController">
<h3 class="page-header">
<small ng-if="remaining()">{{ count }}</small>
</h3>
</div>
help me.
I'm looking forward to a solution.
</div>
change Angular symbo when defining your Angular application module using Angular's $interpolateProvider
var sampleApp = angular.module('sampleApp', [], function($interpolateProvider) {
$interpolateProvider.startSymbol('<%');
$interpolateProvider.endSymbol('%>');
});
and then blade tags will be {{ }}
and angular tags will be <% %>
or anything you want
use @{{angular_varialble}} in blade file
<div id="employee" ng-controller="EmployeesController">
<h3 class="page-header">
<small ng-if="remaining()">@{{ count }}</small>
</h3>
</div>
In theory, you would need to use
@{{angular_variable}}
so the software won't take it as a const. In your case:
@{{ count }}