本文介绍了(angularjs)注入控制器时收到"ReferenceError:未定义$ scope"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试学习AngularJS.我有一个HTML页面,我试图在其中插入模块但出现错误
I have am trying to learn AngularJS. I have a HTML page where I am trying to inject module but getting an error
主要js文件:
var classificationModule = angular.module('mainapp',[]); classificationModule.controller('firstcontroll',function(){ $scope.text="Goodday" });HTML 页面:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <meta name="layout" content="main"/> <title>Classification Toolkit for Grails</title> <script src="ajax.googleapis/ajax/libs/angularjs/1.2.21/angular.js"></script> <asset:javascript src="main.js"/> </head> <body > <div ng-app='mainapp' ng-controller='firstcontroll'> Hello, {{text}} </div> </body> </html>出现以下错误:
ReferenceError: $scope is not defined我不知道我在做什么错.
I dont know what I am doing wrong.
推荐答案尝试在函数中传递 $ scope .
var classificationModule = angular.module('mainapp', []); classificationModule.controller('firstcontroll', function($scope) { $scope.text = "Goodday" }); <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <meta name="layout" content="main" /> <title>Classification Toolkit for Grails</title> <script src="ajax.googleapis/ajax/libs/angularjs/1.2.21/angular.js"></script> <asset:javascript src="main.js" /> </head> <body> <div ng-app='mainapp' ng-controller='firstcontroll'> Hello, {{text}} </div> </body> </html>
更多推荐
(angularjs)注入控制器时收到"ReferenceError:未定义$ scope"
发布评论