-1
我是新來學習angularjs,我想用angularjs前端與YII 2.0。如何在YII 2.0框架中使用angualrjs作爲前端?
我GOOGLE了,但沒有找到任何解決方案,對不起,如果有人問同樣的問題。
使用高級應用程序YII 2.0我已經加入angular.min.js和角度resource.min.js到rootproject /前端/資產/ AppAsset.php
public $js = [
'assets/angularjavascript/angular.min.js',
'assets/angularjavascript/angular-resource.min.js',
];
index.php文件
<html data-ng-app="">
<head>
</head>
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<table>
<tr ng-repeat="x in names">
<td>{{ x.Name }}</td>
<td>{{ x.Country }}</td>
</tr>
</table>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("http://www.w3schools.com/angular/customers_mysql.php")
.success(function (response) {$scope.names = response.records;});
});
</script>
</body>
</html>
錯誤:
ReferenceError: angular is not defined
var app = angular.module('myApp', []);
Error: [$injector:modulerr] http://errors.angularjs.org/1.3.15/$injector/modulerr?p0=myApp&p1=%5B%24injector%3Anomod%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.3.15%2F%24injector%2Fnomod%3Fp0%3DmyApp%0AR%2F%3C%40http%3A%2F%2Flocalhost%2Fyii__project%2Fadvanced%2Ffrontend%2Fweb%2Fassets%2Fangularjavascript%2Fangular.min.js%3A6%3A417%0AOd%2F%3C%2F%3C%2F%3C%40http%3A%2F%2Flocalhost%2Fyii__project%2Fadvanced%2Ffrontend%2Fweb%2Fassets%2Fangularjavascript%2Fangular.min.js%3A21%3A412%0Aa%40http%3A%2F%2Flocalhost%2Fyii__project%2Fadvanced%2Ffrontend%2Fweb%2Fassets%2Fangularjavascript%2Fangular.min.js%3A21%3A53%0AOd%2F%3C%2F%3C%40http%3A%2F%2Flocalhost%2Fyii__project%2Fadvanced%2Ffrontend%2Fweb%2Fassets%2Fangularjavascript%2Fangular.min.js%3A21%3A1%0Ag%2F%3C%40http%3A%2F%2Flocalhost%2Fyii__project%2Fadvanced%2Ffrontend%2Fweb%2Fassets%2Fangularjavascript%2Fangular.min.js%3A35%3A46%0Ar%40http%3A%2F%2Flocalhost%2Fyii__project%2Fadvanced%2Ffrontend%2Fweb%2Fassets%2Fangularjavascript%2Fangular.min.js%3A7%3A300%0Ag%40http%3A%2F%2Flocalhost%2Fyii__project%2Fadvanced%2Ffrontend%2Fweb%2Fassets%2Fangularjavascript%2Fangular.min.js%3A34%3A399%0Aab%40http%3A%2F%2Flocalhost%2Fyii__project%2Fadvanced%2Ffrontend%2Fweb%2Fassets%2Fangularjavascript%2Fangular.min.js%3A38%3A135%0Auc%2Fd%40http%3A%2F%2Flocalhost%2Fyii__project%2Fadvanced%2Ffrontend%2Fweb%2Fassets%2Fangularjavascript%2Fangular.min.js%3A17%3A381%0Auc%40http%3A%2F%2Flocalhost%2Fyii__project%2Fadvanced%2Ffrontend%2Fweb%2Fassets%2Fangularjavascript%2Fangular.min.js%3A18%3A179%0AJd%40http%3A%2F%2Flocalhost%2Fyii__project%2Fadvanced%2Ffrontend%2Fweb%2Fassets%2Fangularjavascript%2Fangular.min.js%3A17%3A1%0A%40http%3A%2F%2Flocalhost%2Fyii__project%2Fadvanced%2Ffrontend%2Fweb%2Fassets%2Fangularjavascript%2Fangular.min.js%3A250%3A429%0AjQuery.Callbacks%2Ffire%40http%3A%2F%2Flocalhost%2Fyii__project%2Fadvanced%2Ffrontend%2Fweb%2Fassets%2Fa462caba%2Fjquery.js%3A3094%3A10%0AjQuery.Callbacks%2Fself.fireWith%40http%3A%2F%2Flocalhost%2Fyii__project%2Fadvanced%2Ffrontend%2Fweb%2Fassets%2Fa462caba%2Fjquery.js%3A3206%3A7%0A.ready%40http%3A%2F%2Flocalhost%2Fyii__project%2Fadvanced%2Ffrontend%2Fweb%2Fassets%2Fa462caba%2Fjquery.js%3A3412%3A1%0Acompleted%40http%3A%2F%2Flocalhost%2Fyii__project%2Fadvanced%2Ffrontend%2Fweb%2Fassets%2Fa462caba%2Fjquery.js%3A3428%3A2%0A
在此先感謝您的幫助。
在代碼中有幾個錯誤,但這是一個極端普遍的問題。 –
您應該在網頁中加載角色腳本。將其包含在頁腳或身體關閉標記之前 – Vineet