
Js后跟 HTML
var app = angular.module('myApp',[]);app.controller('MainCtrl',function($scope) { $scope.name = 'World'; $scope.submit = function() { if ($scope.username && $scope.password) { var user = $scope.username; var pass = $scope.password; if (pass == "admin" && user == "admin@admin.com") { alert("Login Successful"); $window.location.href = "http://Google.com"; //Re-direction to some page } else if (user != "admin@admin.com") { alert("InvalID username"); } else if (pass != "admin" && user == "admin@admin.com") { alert("InvalID password"); } } else { alert("InvalID Login"); } }}); <!DOCTYPE HTML><HTML ng-app="myApp"><head> <script src="http://AJAX.GoogleAPIs.com/AJAX/libs/angularJs/1.4.8/angular.min.Js"></script> <script src="login.Js"></script> <link rel="stylesheet" href="login.CSS"></head><body ng-controller="MainCtrl"> <form> <label>Username:</label> <input type="email" ng-model="username" /> </br> </br> <label></label>Password:</label> <input type="password" ng-model="password" > </br> <button type="submit" ng-click="submit()" >login</button> </form></body></HTML>解决方法 在角度Js中,您可以使用$location.将其注入您的控制器:
app.controller('MainCtrl',function($scope,$location) { ... } 如果你想重定向到谷歌使用其url()方法:
$location.url('http://Google.fr'); 你也可以使用相对url的path()方法:
$location.path('home'); // will redirect you to 'yourDomain.xx/home' https://docs.angularjs.org/api/ng/service/ $位置
总结以上是内存溢出为你收集整理的html – $window.location.href不在AngularJS中工作全部内容,希望文章能够帮你解决html – $window.location.href不在AngularJS中工作所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)