简体   繁体   English

无法弄清楚为什么角度绑定在Codepen脚本中不起作用

[英]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.

相关问题 无法弄清楚为什么angularJS模块无法加载 - Can't figure out why angularJS module won't load 无法弄清楚为什么我的角度视图是空白的 - Can't figure out why my angular view is blank 无法弄清楚为什么ng-resource不会返回数组 - Can't figure out why ng-resource won't return array 无法弄清楚为什么页面在底部加载? Angular UI-Router 自动滚动问题 - Can't figure out why page loads at bottom? Angular UI-Router autoscroll Issue AngularJS:无法弄清楚为什么在使用transclude:&#39;element&#39;进行转换时嵌套的角度指令不被渲染 - AngularJS : Can't figure out why nested angular directive does not get rendered when transcluding with transclude:'element' 无法弄清楚为什么我的角度代码不能与Ionic框架和Intel XDK一起使用 - Can't figure out why my angular code is not working with Ionic framework and Intel XDK 无法弄清楚为什么ng-repeat不排序 - Can't figure out why ng-repeat not sorting 角度路由不起作用 - Angular Routing won't work 为什么工厂不工作? (Angular.js) - Why factory won't Work? (Angular.js) 为什么angular的titlecase过滤器对我不起作用? - Why won't angular's titlecase filter work for me?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM