.when({....}).otherwise({....}在配置路由的时候,otherwrie中通常会配置默认的地址,即便不配置otherwise,Angular也会清除ng-view中的内容。
当使用anchor的时候每次触发锚点,就会修改hash,接着angular就会触发‘路由’处理,这样就致使二者冲突,页面内容发生改变。 浏览器
解决方式是,写一个指令,拦截锚点的浏览器默认行为,手动设置要滚动的距离。 spa
link:function(scope,element,attrs){ element.bind('click',function(e){ e.stopPropagation(); var scrollToElement= $('#'+attrs.scrollToElementId); window.scrollTo(0,endElement.offset().top); }); }