[英]Cannot get AngularJS to work on JSFiddle
I am trying to work with AngularJS on JSFiddle. 我正在尝试在JSFiddle上使用AngularJS。
I've copied other similar projects to the T, but still, JSFiddle is giving me all sorts of errors when I try it in my own. 我已经将其他类似的项目复制到了T,但是当我自己尝试使用JSFiddle时,它仍然给我带来各种错误。 Currently, it is telling me that is doesn't recognize my controller.
目前,它告诉我无法识别我的控制器。
I'd really appreciate if someone could have a look at my really simple Fiddle and tell me why it is not working. 如果有人可以看看我真正简单的小提琴并告诉我为什么它不起作用,我将非常感激。
https://jsfiddle.net/ke10sq2v/ https://jsfiddle.net/ke10sq2v/
Here's the code: 这是代码:
angular.module('App', ['ngAnimate'])
.controller("Ctlr", ['$scope', function($Scope){
$scope.hi = "yolo";
}]);
HTML 的HTML
<div ng-controller="Ctrl" ng-init="showBoxes=false">
<div class="block" ng-show="showBoxes">Block 1</div>
<div class="block" ng-show="showBoxes">Block 2</div>
<button ng-click="showBoxes=!showBoxes">Toggle</button>
<p>Show Boxes: {{showBoxes}} {{hi}}</p>
</div>
CSS 的CSS
.block {
height: 100px;
width: 100px;
background-color: blue;
margin: 15px 10px;
}
A few things: 一些东西:
You forgot to declare the ngApp
directive in the HTML 您忘记了在HTML中声明
ngApp
指令
You spelled Ctrl
wrong in the controller defintion 您在控制器定义中将
Ctrl
拼写错误
You capitalized $Scope
in the controller injection - but tried to reference $scope
您在控制器注入中将
$Scope
大写-但尝试引用$scope
Working fiddle: https://jsfiddle.net/ke10sq2v/1/ 工作提琴: https : //jsfiddle.net/ke10sq2v/1/
IMPORTANT: (as per comment from Jack A. below) You need to select one of the "No wrap" load types for the JavaScript. 重要说明:(根据下面来自Jack A.的评论),您需要为JavaScript选择一种“ No wrap”加载类型。 The default "on load" doesn't work with Angular...
默认的“加载”不适用于Angular ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.