2015-07-19 94 views
11

每当我的页面加载时,在控制台中显示以下错误。未捕获的错误:语法错误,无法识别的表达式:#/ angularjs和jquery

“未捕获错误:语法错误,不能识别的表达式:#/约”

我的代码是如下:

   <li class="active"> 
        <a href="/">Home</a> 
       </li> 
       <li class=""> 
        <a href="#/about" title="About Us">About</a> 
       </li> 
       <li class=""> 
        <a href="#/pricing">Pricing</a> 
       </li> 

它示出了用于所有的初始实例。最初,它显示为#/关于它的第一个,如果我删除关于我们选项卡它将显示价格页链接。

它不是引导选项卡上的问题,这是简单的导航只有

路由代码在app.js:

$routeProvider.when('/', { 
     templateUrl: 'partials/home.html' 
    }).when('/account', { 
     templateUrl: 'partials/account.html', 
    }).when('/terms', { 
     templateUrl: 'partials/terms.html' 
    }).when('/about', { 
     templateUrl: 'partials/about.html' 
    }).otherwise({ 
     redirectTo: '/' 
    }); 

我调试它引导的问题,引导资产净值造成这个问题:“导航导航栏-nav“ 修复此数据目标=”#“,但希望适当的解决此问题

+0

什么是涉及到你的航线JS代码? – ryanlutgen

+0

使用'About' –

+0

试过了太还是同样的错误 – ram

回答

16

这很可能是一个引导问题。尝试使用data-target属性上你的链接像这样

<a href="#/about" data-target="#about" title="About Us">About</a> 
+0

它不是模式,或引导组件,它只是一个导航链接 – ram

+2

这修复我的通过添加数据目标=“#”可以发出问题 – ram

+1

对于所有路由**都可以,除了“/”**:'a(href ='#/',data-target ='#')'。我的路由配置是相同的:'$ routeProvider.when('/',{templateUrl:/views/home/home.html'})''。我做错了什么? –

4

好吧,你得去掉斜线,“/”与你的HTML变,

<a href="#about" title="About Us">About</a> 

如果你想保持斜线,“/”你必须使用data-target属性作为,

<a href="#/about" title="About Us" data-target="#about">About</a> 

更多关于它here

+0

你是指制表符? - 它不是一个引导标签,它只是一个普通的链接 – ram

+0

你试过了吗?你有没有放置'

'? –

+0

对不起,你要求我把ng-view放在哪里,它是头部,我使用ng-include – ram

1

这可能是一种非常罕见的情况,但由于使用Colorbox和location.hash的一些遗留代码,我得到同样的错误。

jQuery(function() {jQuery('.content-row .csc-default a').tooltip({placement:'top'}); 
jQuery('a.gallery').colorbox({ 
    maxWidth:'95%', 
    maxHeight:'95%', 
    slideshow:true, 
    current:' {current}/{total}', 
    opacity:'0.80', 
    transition:'none', 
    speed:'550', 
    slideshowSpeed:'5500', 
    overlayClose:true, 
    fixed:false, 
    escKey:true, 
    arrowKey:true, 
    loop:true, 
    title: function() { return $(this).data('original-title')}, 
    close:'<span class="glyphicon glyphicon-remove"></span>', 
    previous:'<span class="glyphicon glyphicon-chevron-left"></span>', 
    next:'<span class="glyphicon glyphicon-chevron-right"></span>', 
    slideshowStart:'<span class="glyphicon glyphicon-play"></span>', 
    slideshowStop:'<span class="glyphicon glyphicon-pause"></span>', 
    rel: function() { return $(this).data('rel')} 
}); 
if (location.hash) $(location.hash).collapse('show'); //when this line is commented, Angular Route works properly 
}); 

奇怪的是加载页面时链接可查看像localhost/index.html#/main或者干脆重新加载页面,选择任何观点,错误只发生。

3

此问题也发生在角度2项目上。我只是将数据目标=“#”添加到锚链接。它解决了我的问题。

<a data-target="#" [routerLink]="['/link']">my link</a>.

相关问题