Laravel angularjs配置
问题描述:
我尝试包括Angularjs在Laravel,但我不知道我了哪些错误,我得到了错误Laravel angularjs配置
使用未定义的常量名 - 假定“名”
myHead.blad .PHP
<title>Title</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="bower_components/angular/angular.min.js"></script>
<script src="bower_components/angular-route/angular-route.min.js"></script>
<script type="text/javascript" src="app.js"></script>
<script type="text/javascript" src="controllers/homeController.js"></script>
<script type="text/javascript" src="controllers/aboutController.js"></script>
myWelcome.blade.php
<!DOCTYPE html>
<html ng-app="MyApp">
<head>
<?php echo View::make('layouts/head'); ?>
</head>
<body>
<?php echo View::make('layouts/header'); ?>
<div ng-controller="HelloController">Hi {{name}} welcome to AngularJS Tutorial Series</div>
<button class="btn" name="test" value="test">Test</button>
</body>
<?php echo View::make('layouts/footer'); ?>
</html>
Hellocontroller.js
MyApp.controller('HelloController', hello);
function hello($scope)
{
$scope.name = "Test";
}
请告诉我如何配置Angularjs在Laravel
答
插值表达需要改变,如果你想与laravel因为laravel和角工作js都使用相同的{{}}插值符号进行表达exicuition
添加在您确定您的应用程序
var MyApp = angular.module('MyApp', [])
MyApp.config(function($interpolateProvider) {
$interpolateProvider.startSymbol('<%');
$interpolateProvider.endSymbol('%>');
});
代码myWelcome.blade.php
<!DOCTYPE html>
<html ng-app="MyApp">
<head>
<?php echo View::make('layouts/head'); ?>
</head>
<body>
<?php echo View::make('layouts/header'); ?>
<div ng-controller="HelloController">Hi <%name%> welcome to AngularJS Tutorial Series</div>
<button class="btn" name="test" value="test">Test</button>
</body>
<?php echo View::make('layouts/footer'); ?>
</html>
答
请检查到你的代码的问题仍存在与注射,由于你的代码不能正常工作,它的工作与你的代码,请看看
(function(angular) {
'use strict'; var myApp = angular.module('MyApp',[]);
myApp.controller( 'HelloController中',函数($范围){$ = scope.name '测试';
}); })(window.angular);
你没有'变种MyApp的= angular.module( 'MyApp的',[])'? – tanmay
我声明,也公开/ app.js – Develop