尝试学习角度。从教程开始。
我有一个coffeescript文件,在服务器上编译然后缩小。
这有效:
phonecatApp = angular.module('phonecatApp',[])
PhoneListCtrl = ($scope) ->
$scope.phones = [
{
name: 'Nexus S',
snippet: 'Fast just got faster with Nexus S.'
}
{
name: 'Motorola XOOM™ with Wi-Fi',
snippet: 'The Next, Next Generation tablet.'
}
{
name: 'MOTOROLA XOOM™',
snippet: 'The Next, Next Generation tablet.'
}
]
PhoneListCtrl.$inject = [
"$scope"
]
phonecatApp.controller 'PhoneListCtrl', PhoneListCtrl
但是这个(添加箭头“ - >”)不是
->
phonecatApp = angular.module('phonecatApp',[])
PhoneListCtrl = ($scope) ->
$scope.phones = [
{
name: 'Nexus S',
snippet: 'Fast just got faster with Nexus S.'
}
{
name: 'Motorola XOOM™ with Wi-Fi',
snippet: 'The Next, Next Generation tablet.'
}
{
name: 'MOTOROLA XOOM™',
snippet: 'The Next, Next Generation tablet.'
}
]
PhoneListCtrl.$inject = [
"$scope"
]
phonecatApp.controller 'PhoneListCtrl', PhoneListCtrl
我已经尝试了很多,但没有任何作用
HTML看起来像这样
<html ng-app="phonecatApp">
<head>
...
<script src="...com/.../angularjs/1.2.16/angular.min.js"></script>
<script src="js/controllers.js"></script>
</head>
<body>
<div class="container" ng-controller="PhoneListCtrl">
<ul>
<li ng-repeat="phone in phones">
{{phone.name}}
<p>{{phone.snippet}}</p>
</li>
</ul>
</div>
</body>
</html>
答案 0 :(得分:1)
为准备好文件
执行此操作$ ->
var x = 5; // your code here
我认为你不需要这样做,因为加载页面时会有角度引导,除非你在加载DOM之前使用angular.bootstrap()。