不能设置未定义的属性吗

时间:2020-12-27 21:06:47

I just can't figure it out why my html is not working. I have just clone the angular-seed from the github and trying to make some changes to learn more about angular.

我就是弄不明白为什么我的html不能工作。我刚刚克隆了github上的角状种子,并尝试做一些改变来了解更多的角状。

view2.js

view2.js

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

i have just added a single line of code $scope.message and i have call the message in view2.html

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

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>

I am getting the error

我弄错了。

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)

TypeError:无法在Object (http://localhost:8000/app/view2/view2.js:13:15)上设置未定义的属性“message”(http://localhost:8000/app/bower_components/ angle /angular.js:4560:17)。实例化(http://localhost:8000 / app / bower_components /角度/ angular.js:4568:27)在http://localhost:8000 / app / bower_components /角度/角。在invokeLinkFn上(http://localhost:8000/app/bower_components/angular-route/angular-route.js: 9885:26) (http://localhost:8000/app/bower_components/角度/角度/角度/角度/角度/角度/角度/角度/角度/角度/角度/角度/角度/角度/ http://localhost_062779:56(http://localhost:8000 / app / bower_components /角度/ angular.js:7983:16)

I think i am missing something.

我想我漏掉了什么。

1 个解决方案

#1


3  

If you it is minified code then make this change before minification

如果是缩小代码,那么在缩小之前进行修改

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

}]);

#1


3  

If you it is minified code then make this change before minification

如果是缩小代码,那么在缩小之前进行修改

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

}]);