gpt4 book ai didi

javascript - 无法使用 angular.js 执行 Controller 功能

转载 作者:行者123 更新时间:2023-12-03 09:27:22 25 4
gpt4 key购买 nike

我的 Controller 函数根本没有使用 Angular.js 调用。我在下面解释我的代码。

admin.html:

<head ng-app="adminModule">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Welcome to Odia Doctor Admin Panel</title>

<link href='http://fonts.googleapis.com/css?family=Roboto:400,300,500,700,900' rel='stylesheet' type='text/css' />
<link href='http://fonts.googleapis.com/css?family=Lato:300,400,700' rel='stylesheet' type='text/css' />
<link rel="shortcut icon" href="img/favicon.png" type="image/x-icon">
<!-- Styles -->
<link rel="stylesheet" href="font-awesome-4.2.0/css/font-awesome.css" type="text/css" /><!-- Font Awesome -->
<link rel="stylesheet" href="css/bootstrap.css" type="text/css" /><!-- Bootstrap -->
<link rel="stylesheet" href="css/style.css" type="text/css" /><!-- Style -->
<link rel="stylesheet" href="css/responsive.css" type="text/css" /><!-- Responsive -->

</head>
<body style="background-image: url('images/resource/login-bg.jpg')" ng-controller="admincontroller">

<div class="login-sec">
<div class="login-sec">
<div class="login">
<div class="login-form">
<span><img src="images/logo.png" alt="" /></span>
<h5><strong>Identify</strong> Yourself</h5>
<center ng-hide="lStatus">{{loginStatus}}</center>
<form action="#" method="post">
<fieldset><input type="text" placeholder="Username" class="logininputdiv" /><i class="fa fa-user"></i></fieldset>
<fieldset><input type="password" placeholder="Password" class="logininputdiv" /><i class="fa fa-unlock-alt"></i></fieldset>
<label><input type="checkbox" />Remember me</label><button type="button" class="blue" ng-click="adminLogin();">LOG IN</button>
</form>
</div>
<span>Copyright © 2015 Odia Doctor</span>
</div>
</div><!-- Log in Sec -->
<script src="js/angular.min.js" type="text/javascript"></script>
<script src="js/jquery.min.js" type="text/javascript"></script>
<script src="js/adminlogincontroller.js" type="text/javascript"></script>
</body>

</html>

adminlogincontroller.js:

var app = angular.module('adminModule',[]);
app.controller('admincontroller',['$scope','$http',function($scope,$http){
console.log('hello controller');
$scope.lStatus=false;

}])

我需要在页面加载时调用此 Controller 函数。但是没有发生这样的事情。请帮我解决这个问题。

最佳答案

看起来你定义了你的 ng-app<head>而不是<html> .

<head ng-app="adminModule">

所以结果是你的 Controller 不在 Angular 的范围内:)

</head>
<body style="background-image: url('images/resource/login-bg.jpg')" ng-controller="admincontroller">

你应该在 <html> 上声明它

<html ng-app="adminModule">
<head>
...
</head>
<body ng-controller="...">

</body>
</html>

关于javascript - 无法使用 angular.js 执行 Controller 功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31628576/

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