问题描述
限时送ChatGPT账号..我正在尝试在 angular js 项目中使用 require js.我能够显示视图,但问题是我无法在登录"按钮单击时收到警报.实际上我在按钮单击时显示一个警报.>
这是我的代码
http://plnkr.co/edit/jv79297BZLiJpY66rKAc?p=preview
function ctrl($scope, $state) {$scope.login = 函数 () {alert("登录被点击")};}
我想我在控制台上出错了,为什么我无法显示警报?
http://errors.angularjs/1.2.12/ng/areq?p0=LoginCtrl&p1=not%20a%20function%2C%20got%20undefined在错误(本机)
解决方案在文件 bootstrap.js 的 define
块中传递控制器名称就成功了:
define(['ionic', 'app', 'route', 'LoginCtrl'], function (ionic, app) {'使用严格';angular.element().ready(function () {尝试 {控制台日志(应用程序)angular.bootstrap(document, [app.name]);}赶上(e){console.error(e.stack || e.message || e);}});});
您可以在此处
找到更新的plunkerI am trying to use require js in angular js project .I am able to show view but issue is that I am not able to get alert on "Login" button click .Actually I show One alert on button click .
Here is my code
http://plnkr.co/edit/jv79297BZLiJpY66rKAc?p=preview
function ctrl($scope, $state) {
$scope.login = function () {
alert("Login is clicked")
};
}
I think I got error on console that why I am not able to display alert ?
http://errors.angularjs/1.2.12/ng/areq?p0=LoginCtrl&p1=not%20a%20function%2C%20got%20undefined at Error (native)
解决方案Passing the controller name in the define
block of file bootstrap.js did the trick :
define(['ionic', 'app', 'route', 'LoginCtrl'], function (ionic, app) {
'use strict';
angular.element().ready(function () {
try {
console.log(app)
angular.bootstrap(document, [app.name]);
} catch (e) {
console.error(e.stack || e.message || e);
}
});
});
You can find the updated plunker here
这篇关于为什么 angularjs 中不显示警报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论