Angularjs无需单击即可更改视图
我还不熟悉棱角分明,但我很努力地试着让我的头绕过它。 基本上,我只想从一个视图移动到另一个视图,一个功能已经完成。代码如下:Angularjs无需单击即可更改视图,angularjs,Angularjs,我还不熟悉棱角分明,但我很努力地试着让我的头绕过它。 基本上,我只想从一个视图移动到另一个视图,一个功能已经完成。代码如下: App.controller('clientLogin', function ($scope, $http, $route) { $scope.clientLoginBt = function () { var sun = $('#ClientUsername').val(); var spa = $('#ClientPassword').val()
App.controller('clientLogin', function ($scope, $http, $route) {
$scope.clientLoginBt = function () {
var sun = $('#ClientUsername').val();
var spa = $('#ClientPassword').val()
$http({url: "/sources/",
headers: {"X-Appery-Database-Id": dbid},
params: {where: '{"$and" : [{"username": "' + sun + '"}, {"password" : "' + spa + '"}]}'}})
.success(function (data) {
console.log(data.length);
$scope.clientLogggedin = data;
if (data.length > 0) {
$route.clientLogggedin();
} else {
}
})
.error(function (status) {
console.log('data on fail: ' + status);
});
}
});
上面,如果返回的数据有多行,那么用户日志是正确的,我只想更改视图
我试过$location,但不起作用,因为Angular很容易使用,在编码量方面,我看不到任何关于它的信息,除非单击,它会启动控制器
以下是HTML:
<div class="row" ng-controller="clientLogin">
<div class="large-12 medium-12">
<input type="text" id="ClientUsername" placeholder="Enter Username" />
<input type="password" id="ClientPassword" placeholder="Enter Password" />
<button ng-click="clientLoginBt()">Login</button>
</div>
</div>
你知道我做错了什么吗
提前感谢。使用$location的路径方法应该可以做到这一点。由于您希望访问clientLoggedIn.html,因此需要使用匹配的路由(/clientLoggedIn): 确保$location服务已注入到您的应用程序控制器中。这是您可能应该用上面的内容替换的行:
$route.clientLogggedin();
使用$location的路径方法应该可以做到这一点。由于您希望访问clientLoggedIn.html,因此需要使用匹配的路由(/clientLoggedIn): 确保$location服务已注入到您的应用程序控制器中。这是您可能应该用上面的内容替换的行:
$route.clientLogggedin();
使用$location的路径方法应该可以做到这一点。由于您希望访问clientLoggedIn.html,因此需要使用匹配的路由(/clientLoggedIn): 确保$location服务已注入到您的应用程序控制器中。这是您可能应该用上面的内容替换的行:
$route.clientLogggedin();
使用$location的路径方法应该可以做到这一点。由于您希望访问clientLoggedIn.html,因此需要使用匹配的路由(/clientLoggedIn): 确保$location服务已注入到您的应用程序控制器中。这是您可能应该用上面的内容替换的行:
$route.clientLogggedin();
只需检查一个指示器$http调用是否成功。如果您不愿意为
clientLoggedIn.html
添加路由。您可以执行以下操作,只需启用登录页面:
<div class="row" ng-controller="clientLogin">
<div class="large-12 medium-12" ng-hide="sucessfulLogin">
<input type="text" id="ClientUsername" placeholder="Enter Username" />
<input type="password" id="ClientPassword" placeholder="Enter Password"/>
<button ng-click="clientLoginBt()">Login</button>
</div>
<ng-include src="'views/clientLoggedIn.html'" ng-show="sucessfulLogin">
</ng-include>
<!-- or just include the DOM element here if you do not
want a separate html altogether-->
</div>
另外请注意,如果愿意,使用
ng include
指令,您仍然可以在clientLoggedIn.html
中使用单独的控制器。只需在clientLoggedIn.html
中的第一个元素中使用ng controller
,只需检查一个指示器$http调用是否成功。如果您不愿意为clientLoggedIn.html
添加路由。您可以执行以下操作,只需启用登录页面:
<div class="row" ng-controller="clientLogin">
<div class="large-12 medium-12" ng-hide="sucessfulLogin">
<input type="text" id="ClientUsername" placeholder="Enter Username" />
<input type="password" id="ClientPassword" placeholder="Enter Password"/>
<button ng-click="clientLoginBt()">Login</button>
</div>
<ng-include src="'views/clientLoggedIn.html'" ng-show="sucessfulLogin">
</ng-include>
<!-- or just include the DOM element here if you do not
want a separate html altogether-->
</div>
另外请注意,如果愿意,使用
ng include
指令,您仍然可以在clientLoggedIn.html
中使用单独的控制器。只需在clientLoggedIn.html
中的第一个元素中使用ng controller
,只需检查一个指示器$http调用是否成功。如果您不愿意为clientLoggedIn.html
添加路由。您可以执行以下操作,只需启用登录页面:
<div class="row" ng-controller="clientLogin">
<div class="large-12 medium-12" ng-hide="sucessfulLogin">
<input type="text" id="ClientUsername" placeholder="Enter Username" />
<input type="password" id="ClientPassword" placeholder="Enter Password"/>
<button ng-click="clientLoginBt()">Login</button>
</div>
<ng-include src="'views/clientLoggedIn.html'" ng-show="sucessfulLogin">
</ng-include>
<!-- or just include the DOM element here if you do not
want a separate html altogether-->
</div>
另外请注意,如果愿意,使用
ng include
指令,您仍然可以在clientLoggedIn.html
中使用单独的控制器。只需在clientLoggedIn.html
中的第一个元素中使用ng controller
,只需检查一个指示器$http调用是否成功。如果您不愿意为clientLoggedIn.html
添加路由。您可以执行以下操作,只需启用登录页面:
<div class="row" ng-controller="clientLogin">
<div class="large-12 medium-12" ng-hide="sucessfulLogin">
<input type="text" id="ClientUsername" placeholder="Enter Username" />
<input type="password" id="ClientPassword" placeholder="Enter Password"/>
<button ng-click="clientLoginBt()">Login</button>
</div>
<ng-include src="'views/clientLoggedIn.html'" ng-show="sucessfulLogin">
</ng-include>
<!-- or just include the DOM element here if you do not
want a separate html altogether-->
</div>
另外请注意,如果愿意,使用
ng include
指令,您仍然可以在clientLoggedIn.html
中使用单独的控制器。只需在执行此操作的clientLoggedIn.html
中的第一个元素中使用ng controller
。不知道为什么它以前从来没有起过作用。但这一次确实做到了。我知道这会很简单,就是这样。不知道为什么它以前从来没有起过作用。但这一次确实做到了。我知道这会很简单,就是这样。不知道为什么它以前从来没有起过作用。但这一次确实做到了。我知道这会很简单,就是这样。不知道为什么它以前从来没有起过作用。但这一次确实做到了。我知道这会很简单。我真的很喜欢这个解决方案,谢谢你分享。很高兴它很有帮助。当您提到我也将其添加到配置中时,我认为我可以使用$route访问它,我假设您必须添加一个路由来访问页面,而此时不需要添加路由。因此,我提出了以下简单的解决方案:)@AndrewWalkerI似乎确实收到了一个错误:error:[$parse:syntax]http://errors.angularjs.org/1.2.15/$parse/syntax?p0=views&p1=is%20an%20意外的%20token&p2=2&p3=%2Fviews%2FclientLoggedIn.html&p4=views%2FclientLoggedIn.html出错(本机)
Yes,必须在此处提供到clientLoggedIn.html
的相对路径。如果这是一个web应用程序(javaish示例),则必须使用类似于js/views/clientLoggedIn.html
的内容,它是相对于应用程序的,而不是相对于父html的目录位置。我希望我能说清楚。是的,这就是我提到的,必须提供一个应用程序到html的相对路径才能访问html。另请注意,用法类似于src=“'relative/path/to/html'”
双引号内的单引号。非常喜欢此解决方案,感谢您分享。很高兴它对您有所帮助。当您提到我也将其添加到配置中时,我认为我可以使用$route访问它,我假设您必须添加一个路由来访问页面,而此时不需要添加路由。因此,我提出了以下简单的解决方案:)@AndrewWalkerI似乎确实收到了一个错误:error:[$parse:syntax]http://errors.angularjs.org/1.2.15/$pa