不能设置未定义的属性

Can not set property of undefined

本文关键字:属性 未定义 设置 不能      更新时间:2023-09-26

我只是想不通为什么我的html不起作用。我刚刚从github克隆了角度种子,并尝试进行一些更改以了解有关角度的更多信息。

视图2.js

.controller('View2Ctrl', [function($scope) {
  $scope.message='hello every one';
}]);

我刚刚$scope.message中添加了一行代码,并且我用view2.html调用了该消息

视图2.html

<p>This is the partial for view 2.</p>
<h1>hello</h1>
<p>{{message}}</p>
<p>
  Showing of 'interpolate' filter:
  {{ 'Current version is v%VERSION%.' | interpolate }}
</p>

我收到错误

类型错误: 无法设置未定义的属性"消息" 在新 (http://localhost:8000/app/view2/view2.js:13:15) 调用时 (http://localhost:8000/app/bower_components/angular/angular.js:4560:17) at Object.instanceiate (http://localhost:8000/app/bower_components/angular/angular.js:4568:27) 在 http://localhost:8000/app/bower_components/angular/angular.js:9440:28 在链接 (http://localhost:8000/app/bower_components/angular-route/angular-route.js:985:26) at invokeLinkFn (http://localhost:8000/app/bower_components/angular/angular.js:9079:9) at nodeLinkFn (http://localhost:8000/app/bower_components/angular/angular.js:8566:11) at compositeLinkFn (http://localhost:8000/app/bower_components/angular/angular.js:7965:13) at publicLinkFn (http://localhost:8000/app/bower_components/angular/angular.js:7845:30) at boundTranscludeFn (http://localhost:8000/app/bower_components/angular/angular.js:7983:16)

我想我错过了一些东西。

如果你是缩小的代码,那么在缩小之前进行此更改

.controller('View2Ctrl', ['$scope',function($scope) {   // note $scope added
$scope.message='hello every one';
}]);