我是Angularjs的新手,并且多年来一直没有做任何代码。我开始使用Angularjs重新设置我的网站。我有一个主页面和一个关于页面,用户通过ng-click(或点击空间)通过ngRoute获取。进入about页面后,用户可以通过单击页面上的某个位置返回,依此类推。
App.js
var app = angular.module("MyApp", ["ngRoute"]);
app.config(function($locationProvider, $routeProvider) {
$routeProvider
.when("/teaser", {
controller:"teaserCtrl",
templateUrl:'teaser.html'
})
.when("/about", {
controller:"aboutCtrl",
templateUrl: "about.html"
})
.otherwise({
redirectTo:"/teaser"
})
});
app.controller("mainCtrl", function($scope, $http, $location) {
$scope.v = {
inverted: false,
display: true,
offwhite: true,
}
$scope.$on("space", function() {
if ($scope.v.teaser) {
$location.path("/about")
$scope.v.teaser = false
} else {
$location.path("/teaser")
$scope.v.teaser = true
}
$scope.$apply()
})
$scope.goHome = function(){
$scope.$broadcast("goHome")
}
});
app.directive("ngMobileClick", [function () {
return function (scope, clickElement, attrs) {
clickElement.bind("touchstart click", function (e) {
e.preventDefault();
e.stopPropagation();
scope.$apply(attrs["ngMobileClick"]);
});
}
}])
HTML
<body ng-controller="mainCtrl as main" ng-mobile-click="goHome()" ng-class="{inverted: v.inverted, bg: v.offwhite}" space>
<div class="content" ng-view ng-hide="v.display"></div>
//My body code
<script ng-init="sw = 'some website'; id="about.html" type="text/ng-template">
<div class="about">
<p class="text" ng-click="next(); $event.stopPropagation()">
<p>some text</p>
<br>
<a ng-href="{{mail}}" ng-click="$event.stopPropagation()">some address</a>
</p>
</div>
</script>
</body>
about页面的代码写入脚本,并且有超链接(ng-href)。现在我的问题:正如你所看到的,我将ng-click更改为ng-mobile-click以获取正文部分。如果我也在脚本中为超链接更改它,我发现一些奇怪的事情,我无法弄清楚(链接更改为悬停颜色,但仍然没有重定向到ng-href。
对于桌面版,点击是触发ngRoute,但我也可以点击链接。对于移动版本,这是不可能的。我有什么想法可以解决这个问题吗?我知道,没有可能的悬停,但不知何故,我需要在移动设备上检测超链接,而不是重定向到主页。
正如我所说:这是我第一次使用Angularjs,我暂时没有做任何代码,请尽可能清楚!
还有另一个teaser / about的控制器,我没有放在这里,以及keyup的指令。
有任何想法或建议吗?非常感谢你!