2017-03-06 59 views
0

我嘗試包括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"; 
} 

請告訴我如何配置AngularjsLaravel

+0

你沒有'變種MyApp的= angular.module( 'MyApp的',[])'? – tanmay

+0

我聲明,也公開/ app.js – Develop

回答

0

插值表達需要改變,如果你想與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> 
+0

它打印這個嗨<%name%>歡迎來到AngularJS教程系列 – Develop

+0

你有沒有在app.js中設置interpolateprovider.startSymbol或interpolateprovider.endSymbol配置代碼? –

+0

感謝它的工作,請你解釋是什麼原因 – Develop

0

請檢查到你的代碼的問題仍存在與注射,由於你的代碼不能正常工作,它的工作與你的代碼,請看看

(function(angular) { 

'use strict'; var myApp = angular.module('MyApp',[]);

myApp.controller( 'HelloController中',函數($範圍){$ = scope.name '測試';

}); })(window.angular);

https://plnkr.co/edit/30nM20o7MHrxPifVu9Ig?p=preview