如何在YII 2.0框架中使用angalrjs作为前端
How to use angualrjs for front-end with YII 2.0 framework?
我刚开始学习angularjs,我想用angularjs作为前端使用YII 2.0。
我用谷歌搜索了一下,但没有找到任何解决方案,如果有人问同样的问题,我很抱歉。
使用高级应用程序YII 2.0我已将angular.min.js和angular-resource.min.js添加到rootproject/frontend/assets/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
提前感谢您的帮助。
对不起,如果我问了愚蠢的问题,但作为新的角js我没有找到任何答案。现在了解它的功能。
实际上,我正在搜索如何将本地angular.js包含到YII 2.0框架中,我自己做了,Vineet也是对的。
需要包含一个angular.js文件,或者为站点的每个页面布局。
将其包含在布局文件的head标签中
<script src="/root/yourjs_folder/angular.min.js"></script>
这可以帮助那些可能面临同样问题的人。
再次感谢。
相关文章:
- 可以前端maven插件使用节点,npm已经安装
- 为什么react/redux前端项目在package.json中包含生产依赖项
- 从REST服务器和Coffeescapet前端开始
- 使用angular js在前端下载文件
- 如何在服务器控制台上打印前端日志消息
- 在前端javascript应用程序中使用DI容器有意义吗
- $interval不允许我更新前端
- 如何使用python后端和web前端提供braintree客户端令牌
- API和前端开发
- 如何刷新表单的yii2前端验证
- 展示纯js应用程序前端的最佳架构是什么
- Shopify javascript api来自商店的前端
- 让 WebStorm 识别后端和前端 JavaScript 文件
- 如何在 JSF 中将 JS 函数作为 JSON 属性传递给前端
- React服务器端渲染在前端重新渲染
- 在汇编中的yaml前端创建复杂的数据模型
- 如何测试前端JavaScript库并与Travis集成
- 如何访问Bokeh's数据并从外部触发前端上的事件
- 如何确保对前端和其他服务器开放的API的安全性
- 如何在YII 2.0框架中使用angalrjs作为前端