laravel 使用未定义的常量 - 假定的 id

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22996760/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 09:20:47  来源:igfitidea点击:

Use of Undefined Constant - assumed id

javascriptphpangularjslaravel

提问by Chris

I am new to angularjs and am having some trouble implementing a simple checklist.

我是 angularjs 的新手,在实施简单的清单时遇到了一些麻烦。

<html lang="en" ng-app>
<body>
<div ng-controller="IdController" class="id-contain">

<ul>
    <li ng-repeat="id in ids">{{ id.body }}</li>
</ul>

</div>
</body>
</html>

and in my main.jsI have

在我的main.js我有

function IdController($scope) {
$scope.id = [
    { body: 'some' },
    { body: 'boiler' },
    { body: 'plate' }
];
}

However, when I load the page, i get Use of undefined constant id - assumed 'id'Any ideas on where I could have gone wrong?

但是,当我加载页面时,我得到Use of undefined constant id - assumed 'id'了关于我可能出错的地方的任何想法?

Edit: I have adjusted the name in the controller from $scope.idto $scope.idsto no avail and when I change the {{}} to [[]] it loads [[ id.body ]] 3 times, but not the value. When I run it with {{}} it is giving me the same error and is parsed as <?php echo id.body; ?>

编辑:我已将控制器中的名称从$scope.idto调整为$scope.ids无效,当我将 {{}} 更改为 [[]] 时,它会加载 [[ id.body ]] 3 次,但不是值。当我用 {{}} 运行它时,它给了我同样的错误并被解析为<?php echo id.body; ?>

回答by AliRNazari

Use @before your angular {{}}blocks:

@在您的角度{{}}块之前使用:

Your code would be like:

您的代码将类似于:

    <html lang="en" ng-app>
    <body>
    <div ng-controller="IdController" class="id-contain">

    <ul>
        <li ng-repeat="id in ids"> @{{ id.body }} </li>
    </ul>

    </div>
    </body>
    </html>

回答by axelduch

That's a problem with blade, you can change laravel's config for blade template token from {{}} to something else like [[]]

这是刀片的问题,您可以将刀片模板令牌的 laravel 配置从 {{}} 更改为其他类似 [[]]

Blade::setContentTags('[[', ']]');
Blade::setEscapedContentTags('[[[', ']]]');

Plus, in your angularjs code you should rename $scope.idto $scope.idsin your controller

另外,在您的 angularjs 代码中,您应该在控制器中重命名$scope.id$scope.ids

UPDATEBlade tokens

更新刀片令牌

EDITOR you can override angular's tags delimiters

编辑或者您可以覆盖 angular 的标签分隔符

DEMO

演示

HTML:

HTML:

<div ng-app="main">
        <div ng-controller="IdController" class="id-contain">
        <ul>
                <li ng-repeat="id in ids">[[id.body]]</li>
            </ul>
    </div>
</div>

JS:

JS

angular.module('main', [])
.config(function ($interpolateProvider) {
    $interpolateProvider.startSymbol('[[');
    $interpolateProvider.endSymbol(']]');
})
.controller('IdController', function ($scope) {
    $scope.ids = [
        { body: 'some' },
        { body: 'boiler' },
        { body: 'plate' }
    ];
});

回答by afarazit

You html is parsed with the blade parser, if you dont need this page to be parsed with blade parser rename your file from myfield.blade.phpto myfile.php

您的 html 是使用刀片解析器解析的,如果您不需要使用刀片解析器解析此页面,请将您的文件重命名myfield.blade.phpmyfile.php