gpt4 book ai didi

javascript - 如何在 Laravel Blade 中使用 Angular 变量

转载 作者:行者123 更新时间:2023-12-04 20:36:04 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





How to implement AngularJS app in Laravel Blade

(6 个回答)


3年前关闭。




我是 Angular Js 的新手。

在 Blade 文件中使用 Angular 变量,我收到以下错误:

Use of undefined constant count - assumed 'count' (View: C:\xampp\htdocs\angularjsLaravel\resources\views\testing.blade.php)



我的代码,

应用程序.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>

帮我。

我期待着一个解决方案。

最佳答案

从理论上讲,您需要使用

@{{angular_variable}}



所以软件不会把它当作一个常量。在你的情况下:

@{{ count }}

关于javascript - 如何在 Laravel Blade 中使用 Angular 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50836633/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com