我有许多标签,我处理特殊逻辑,因此不会发生位置栏地址更改.我有以下内容
<a href="#">Home</a>
Run Code Online (Sandbox Code Playgroud)
这表现得如预期的那样,即当鼠标悬停在按钮上但点击然后开始路线改变时它会给我手形鼠标指针.我希望能够阻止这一点.
我试过删除href或设置href="",似乎有一些成功,但它在悬停时给出了意想不到的结果.
这里的最佳做法是什么?我必须删除href吗?那么我需要使用CSS设置选项卡的样式,以便在悬停时给我鼠标指针?如果我确实离开了href="#"链接,那么这会导致路由更改,这不是我想要的.
我实际上ngClick为每个标签处理我的登录.这个逻辑不能改变路线.
有任何想法吗?
我正在使用角度js单页应用程序.我有页眉和页脚的共同点,我的ng-view根据路由而变化.现在我需要一个具有不同页眉和页脚的页面.如何修改当前页面以包含它.
我的页面有ng-include ="shell.html",shell.html有ng-include ="topnavigation.html"和ng-view ="about.html"
我的ng-view指向基于路由的不同模板.例如:ng-view ="contact.html"
所以我run在angularjs中有这个功能(运行AngularJS v1.2.26)
.run(function(....) {
authService.authCheck();
$rootScope.$on('$routeChangeStart', function(event, next, current) {
if (next.requireLogin) {
if (!authService.isLoggedIn()) {
$location.path('/login');
event.preventDefault();
}
}
});
})...
Run Code Online (Sandbox Code Playgroud)
当直接访问需要身份验证的URL时,例如http://127.0.0.1:8080/secret,该函数总是重定向到登录路径,在调试它一段时间后,它会一直评估为false.访问默认页面然后转到指定的路由它运行没有任何问题.
这是我的一部分 authService
this.authCheck = function() {
$http({
method: 'PUT',
url: '/api/login'
}).
success(function(data, status, headers, config) {
if (status === 200) {
userIsAuthenticated = true;
} else {
userIsAuthenticated = false;
}
$rootScope.loginStatus = userIsAuthenticated;
}).
error(function(data, status, headers, config) {
userIsAuthenticated = false;
$rootScope.loginStatus = userIsAuthenticated;
});
};
this.isLoggedIn = function() { …Run Code Online (Sandbox Code Playgroud) 我正在制作Nodejs和angular js应用程序.当有人在网址上输入并输入网页时,我不得不加载页面.它工作正常,直到我还制作了一个脚本重定向到404错误页面.现在的问题是两个脚本只有一个标准有效.当404重定向工作时,我无法访问在浏览器上键入url的页面,当它工作时,404页面被重定向到索引.HTML.
这是我使用的两个脚本.
app.use(function(req, res) {
res.render('404', {layout: false, title: '404: File Not Found'});
});
app.use('/*', function (req, res) {
res.sendFile(__dirname + '/public/index.html');
});
Run Code Online (Sandbox Code Playgroud)
我在这做错了吗?除此之外,当我从导航中点击它时,我也有我的一般路线在角应用程序中工作正常.
所以我有一个使用传单库实例化的地图对象.地图实例在单独的模板中创建,并以这种方式路由: -
var app = angular.module('myApp', ['ui', 'ngResource']);
app.config(function ($routeProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/map.html',
controller: 'MapCtrl'
})
.otherwise({
redirectTo: '/'
});
});
Run Code Online (Sandbox Code Playgroud)
当我想要处理"搜索/过滤"并在搜索我希望在地图实例上加载的对象时控制GET参数时,问题就开始了.
这是我实现的一个简单的过滤函数,它根据用户点击的选定值(在下拉列表中)触发.
$scope.setFilter = function (fname, fvalue) {
console.log("Setting " + fname + " to " + fvalue);
var search_string = $location.search();
search_string[fname] = fvalue;
$location.search(search_string);
};
Run Code Online (Sandbox Code Playgroud)
浏览器地址栏的url会按照我的预期更新,但原始(传单)地图对象会"更新"并从视图中消失.这不是我想要的.
如何防止这种情况发生或控制此过程,以便仍可以看到地图?
我试过在SO找到了多个解决方案,但我显然失去了一些东西作为不管什么我尝试,我不能让粒子视图来改变表单提交的(或点击按钮)的基础.
这是代码:
propertyControllers.controller('HomeCtrl', ['$scope', 'SearchData', '$location',
function($scope, SearchData, $routeParams, $location) {
SearchData.set('postcode', $scope.postcode);
SearchData.set('radius', $scope.radius);
SearchData.set('minBeds', $scope.minBeds);
SearchData.set('minPrice', $scope.minPrice);
$scope.submit = function() {
$location.path('/properties');
}
}]);
Run Code Online (Sandbox Code Playgroud)
并在home.html部分
<input type="submit" class="topcoat-button--cta" value="Search">
Run Code Online (Sandbox Code Playgroud)
我的路由配置
var propertyApp = angular.module('propertyApp', [
'ngResource',
'ngRoute',
'propertyControllers'
]);
propertyApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/home', {
templateUrl: 'partials/home.html',
controller: 'HomeCtrl'
}).
when('/properties', {
templateUrl: 'partials/property-list.html',
controller: 'PropertyListCtrl'
}).
when('/properties/:propertyId', {
templateUrl: 'partials/property-detail.html',
controller: 'PropertyDetailCtrl'
}).
otherwise({
redirectTo: 'home'
});
}]);
Run Code Online (Sandbox Code Playgroud)
有人能指出我正确的方向吗?文档似乎过于复杂,我发现的所有简单例子都做我正在做的事情......
我刚刚开始研究AngularJS并遇到了如下问题
我已经创建了一个app.js代码
var myApp = angular.module("myApp",[]);
myApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.when("/getAnimals",{
templateUrl: "templates/showAnimals.html",
controller:"animalController"
});
$routeProvider.when("/getBirds",{
templateUrl: "templates/showBirds.html",
controller: "birdController"
});
}]);
myApp.controller("animalController",function($scope){
$scope.message = "Hello Animal World";
});
myApp.controller("birdController",function($scope){
$scope.message = "Hello Bird World";
});
Run Code Online (Sandbox Code Playgroud)
还有一个index.html
<!DOCTYPE html>
<html ng-app = "myApp">
<head>
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.min.js"></script>
<script src = "app.js"></script>
</head>
<body>
<div>
<a href = "#getAnimals">Click Here to get Animals</a><br>
<a href = "#getBirds">Click Here to get Birds</a><br>
</div>
<p ng-view></p>
</body>
Run Code Online (Sandbox Code Playgroud)
但我发现这个页面没有加载,并在我检查时显示一个巨大的错误.我实际上并不了解那里发生的事情.但经过几个小时的破解,而不是给CDN我已经添加了另一个CDN即
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script> …Run Code Online (Sandbox Code Playgroud) 我在我的asp.net应用程序中执行angularjs路由.我有一个文件夹名称模板,包含3个html页面Home,About,Error.这是我的app.js文件
var app = angular.module('myApp', ['ngRoute','ngAnimate']);
app.controller('HomeController', function ($scope) {
$scope.Message = "We are in home page";
});
app.controller('AboutController', function ($scope) {
$scope.Message = "We are in about page";
});
app.controller('ErrorController', function ($scope) {
$scope.Message = "404 page not found";
});
app.config(['$routeProvider', '$locationProvider', function ($routeProvider, $locationProvider) {
$routeProvider.
when('/', {
redirectTo: function () {
return '/home';
}
}).
when('/home', {
templateUrl: '/template/Home.html',
controller: 'HomeController'
}).
when('/about', {
templateUrl: '/template/About.html',
controller: 'AboutController'
}).
when('/error', {
templateUrl: '/template/Error.html',
controller: 'ErrorController'
}).
otherwise({ …Run Code Online (Sandbox Code Playgroud) asp.net asp.net-mvc asp.net-mvc-4 angularjs angularjs-routing
我正在使用UI-Router(-extras)开发AngularJs应用程序,其中我使用以下设置:
.state('root', {
url: '/{language:(?:nl|en)}',
views: {
'root': {
templateUrl: 'app/root/root.html',
controller: 'RootController'
}
}
})
.state('root.main', {
views: {
'main': {
templateUrl: 'app/main/main.html',
controller: 'MainController'
}
},
sticky: true
})
.state('root.modal', {
url: '/{locale:(?:nl|fr)}',
views: {
'modal': {
templateUrl: 'app/modal/modal.html',
controller: 'ModalController'
}
}
})
Run Code Online (Sandbox Code Playgroud)
根状态定义URL中的语言.此外,我有几个模态和主要状态,它们有自己的URL(即root.main.home=> /en/home).
现在我想要一些没有URL的模态.如何让状态忽略他父母的URL?
angularjs angularjs-routing angular-ui-router angular-ui-router-extras
这是我用于我的ui-router的配置:
.state('parent', {
url: '/child1'
controller: ParentController,
abstract: true
})
.state('parent.child1', {
url: ''
})
.state('parent.child2', {
url: '/child2'
})
Run Code Online (Sandbox Code Playgroud)
我想要一个我想要默认的/ child1网址,所以我将父级设为抽象,子状态网址为"空".
所以我希望当用户访问child2状态时,父url会被替换而不是附加它.我怎样才能实现这一目标?