gpt4 book ai didi

html - $范围未定义

转载 作者:搜寻专家 更新时间:2023-10-31 22:13:01 27 4
gpt4 key购买 nike

我一定是遗漏了一些简单的东西。我收到错误 $scope is not defined in plunker。错误在哪里?我已经声明了模块、 Controller 和依赖项我看不出错误在哪里。

    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>

最佳答案

你必须在你的 Controller 声明中注入(inject) $scope

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

缩小安全版本:

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

关于html - $范围未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25816493/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com