gpt4 book ai didi

javascript - 无法设置未定义的属性

转载 作者:行者123 更新时间:2023-11-29 19:14:50 25 4
gpt4 key购买 nike

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

view2.js

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

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

view2.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>

我遇到了错误

TypeError: Cannot set property 'message' of undefined at new (http://localhost:8000/app/view2/view2.js:13:15) at invoke (http://localhost:8000/app/bower_components/angular/angular.js:4560:17) at Object.instantiate (http://localhost:8000/app/bower_components/angular/angular.js:4568:27) at http://localhost:8000/app/bower_components/angular/angular.js:9440:28 at link (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';

}]);

关于javascript - 无法设置未定义的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36170262/

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