(angularjs)注入控制器时收到"ReferenceError:未定义$ scope"

编程入门 行业动态 更新时间:2024-10-28 21:25:06
本文介绍了(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"

本文发布于:2023-10-24 00:12:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1522410.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制器   未定义   angularjs   quot   scope

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!