我正在编写一个小型AngularJS应用程序,它具有登录视图和主视图,配置如下:
$routeProvider
.when('/main' , {templateUrl: 'partials/main.html', controller: MainController})
.when('/login', {templateUrl: 'partials/login.html', controller: LoginController})
.otherwise({redirectTo: '/login'});
Run Code Online (Sandbox Code Playgroud)
我的LoginController检查用户/传递组合并在$ rootScope上设置一个反映这个的属性:
function LoginController($scope, $location, $rootScope) {
$scope.attemptLogin = function() {
if ( $scope.username == $scope.password ) { // test
$rootScope.loggedUser = $scope.username;
$location.path( "/main" );
} else {
$scope.loginError = "Invalid user/pass.";
}
}
Run Code Online (Sandbox Code Playgroud)
一切正常,但如果我访问http://localhost/#/main
我最终绕过登录屏幕.我想写一些类似"每当路由改变时,如果$ rootScope.loggedUser为null然后重定向到/ login"
...
......等一下 我能以某种方式听路线变化吗?无论如何我会发布这个问题并继续寻找.
我有一个类似以下的XML:
<documentation>
This value must be <i>bigger</i> than the other.
</documentation>
Run Code Online (Sandbox Code Playgroud)
使用JDOM,我可以得到以下文本结构:
Document d = new SAXBuilder().build( new StringReader( s ) );
System.out.printf( "getText: '%s'%n", d.getRootElement().getText() );
System.out.printf( "getTextNormalize: '%s'%n", d.getRootElement().getTextNormalize() );
System.out.printf( "getTextTrim: '%s'%n", d.getRootElement().getTextTrim() );
System.out.printf( "getValue: '%s'%n", d.getRootElement().getValue() );
Run Code Online (Sandbox Code Playgroud)
这给了我以下输出:
getText: '
This value must be than the other.
'
getTextNormalize: 'This value must be than the other.'
getTextTrim: 'This value must be than the other.'
getValue: '
This value must be bigger than the other.
' …
Run Code Online (Sandbox Code Playgroud)