[英]Can't figure out why angular binding won't work in codepen script
I'm trying to use angular in codepen, which it seems to support, but I can't bind to my controller's $scope
object for some reason. 我正在尝试在似乎支持的codepen中使用angular,但是由于某种原因我无法绑定到控制器的$scope
对象。 I've tried a couple different versions of angular via cdn
and there are other pens I've seen that are able to successfully use angular. 我通过cdn
尝试了几个不同版本的angular,还有其他一些我可以成功使用angular的笔。 Can anyone tell me why my implementation isn't working? 谁能告诉我为什么我的实现无法正常工作? Here is the pen . 这是笔 。 the version of angular used is 1.4.0
. 使用的angular版本是1.4.0
。
Here is the html code: 这是html代码:
<div class="container" ng-app="App">
<div class="row" ng-controller="catControl">
<div class="col-md-12">
<div class="well">
{{2 + 2}} </br>
{{'cat'}} </br>
{{$scope.cat}} <!-- Why doesnt this one work? -->
</div>
</div>
</div>
</div>
and here is the JS code: 这是JS代码:
var App = angular.module("App", [])
.controller("catControl", function($scope) {
$scope.cat = 'cat';
});
Thanks. 谢谢。
You need learn more about $scope
. 您需要了解有关$scope
更多信息。 We never user {{$scope.key}}
in view. 我们永远不会在视图中使用{{$scope.key}}
。 Instead we we use just {{key}}
in View 相反,我们在View中仅使用{{key}}
Your code should be 您的代码应为
<div class="container" ng-app="App">
<div class="row" ng-controller="catControl">
<div class="col-md-12">
<div class="well">
{{2 + 2}} </br>
{{'cat'}} </br>
{{$scope.cat}} <!-- This will not work -->
{{cat}} <!-- This will work -->
</div>
</div>
</div>
</div>
learn more about scope at This link & This Link 在此链接和此链接中了解有关范围的更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.