Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 未定义$scope_Html_Angularjs - Fatal编程技术网

Html 未定义$scope

Html 未定义$scope,html,angularjs,Html,Angularjs,我一定错过了一些简单的东西。我发现错误$scope未在plunker中定义。错误在哪里?我已经声明了模块、控制器和依赖项,我看不出错误在哪里 var phonecatApp = angular.module('phonecatApp', [$scope]); phonecatApp.controller('PhoneListCtrl', function () { $scope.phones = [ {'name': 'Nexus S', 'snippet': '

我一定错过了一些简单的东西。我发现错误$scope未在plunker中定义。错误在哪里?我已经声明了模块、控制器和依赖项,我看不出错误在哪里

    var phonecatApp = angular.module('phonecatApp', [$scope]);

phonecatApp.controller('PhoneListCtrl', function () {
  $scope.phones = [
    {'name': 'Nexus S',
     'snippet': 'Fast just got faster with Nexus S.',
     'age': 1},
    {'name': 'Motorola XOOM™ with Wi-Fi',
     'snippet': 'The Next, Next Generation tablet.',
     'age': 2},
    {'name': 'MOTOROLA XOOM™',
     'snippet': 'The Next, Next Generation tablet.',
     'age': 3}
  ];

  $scope.orderProp = 'age';
});

    <html ng-app='phonecatApp'>
    <head>
      <title>My Angular App</title>
      <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script>
      <script src="script.js"></script>
    </head>
    <body>
    <div ng-controller="PhoneListCtrl">Search: <input ng-model="query">
  Sort by:
  <select ng-model="orderProp">
    <option value="name">Alphabetical</option>
    <option value="age">Newest</option>
  </select>


  <ul class="phones">
    <li ng-repeat="phone in phones | filter:query | orderBy:orderProp">
      <span>{{phone.name}}</span>
      <p>{{phone.snippet}}</p>
    </li>
  </ul></div>
    </body>
  </html>
var phonecatApp=angular.module('phonecatApp',[$scope]);
phonecatApp.controller('PhoneListCtrl',函数(){
$scope.phones=[
{'name':'Nexus S',
“snippet”:“Nexus S的速度更快了。”,
“年龄”:1},
{'name':'motorolaxoom™ 使用Wi-Fi’,
“snippet”:下一代平板电脑,
“年龄”:2},
{'name':'motorolaxoom™',
“snippet”:下一代平板电脑,
“年龄”:3}
];
$scope.orderProp='age';
});
我的Angular应用程序
搜索:
排序方式:
按字母顺序排列的
最新的
  • {{phone.name} {{phone.snippet}


您必须在控制器声明中注入
$scope

phonecatApp.controller('PhoneListCtrl', function ($scope) {
小型化安全版本:

phonecatApp.controller('PhoneListCtrl', ["$scope", function ($scope) {

尝试在控制器中插入作用域:

phonecatApp.controller('PhoneListCtrl', function ($scope) {
  $scope.phones = [
    {'name': 'Nexus S',
     'snippet': 'Fast just got faster with Nexus S.',
     'age': 1},
    {'name': 'Motorola XOOM™ with Wi-Fi',
     'snippet': 'The Next, Next Generation tablet.',
     'age': 2},
    {'name': 'MOTOROLA XOOM™',
     'snippet': 'The Next, Next Generation tablet.',
     'age': 3}
  ];

  $scope.orderProp = 'age';
});
最好按照以下方式定义控制器和模块声明:

angular.module('phonecatApp').controller('PhoneListCtrl', ['$scope', 
function($scope) {
}]);
工作冲击器:


即使像这样简单的事情也行不通。这与plunker有关吗?你的脚本应该在角度依赖性之后看看我在IE和Chrome中测试的plunker,这刚刚解决了一个错误,我花了大约五个小时在这两种浏览器上工作。我不得不使用缩小安全版本,但我不知道为什么它能工作。“你能帮我理解你回答中的内容吗?”@ArbirryStringofletters-这比我在评论中解释得更好:谢谢你对这么一个老问题的新评论做出的快速回应。这篇文章看起来很有前途@任意排列的字母-没问题!很高兴你解决了这个问题