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
Use of Undefined Constant - assumed id
提问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.js
I 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.id
to $scope.ids
to 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.id
to调整为$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.id
to $scope.ids
in your controller
另外,在您的 angularjs 代码中,您应该在控制器中重命名$scope.id
为$scope.ids
UPDATEBlade tokens
更新刀片令牌
EDITOR you can override angular's tags delimiters
编辑或者您可以覆盖 angular 的标签分隔符
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.php
to myfile.php
您的 html 是使用刀片解析器解析的,如果您不需要使用刀片解析器解析此页面,请将您的文件重命名myfield.blade.php
为myfile.php