ui-router: Get "TypeError: Cannot read property 'match' of undefined" when using ng-attr-ui-sref

Hi there,

I only want to add the ui-sref attribute IF {{item.state}} is defined. That’s what ng-attr is for. But when I use it on on ui-sref, like so ng-attr-ui-sref={{item.state}}, it works great in the DOM but in the console I get TypeError: Cannot read property 'match' of undefined. It only throws this error when I use ng-attr on ui-sref.

<div class="list-group">
  <a 
        ng-attr-ui-sref="{{item.state}}" 
        ng-repeat="item in dynamicPopover.items" 
        ng-attr-ng-click="item.click($event, object.id)" 
        class="list-group-item">
    <i class="fa fa-{{item.icon}}"></i>
    {{item.title}}
    <paper-ripple fit></paper-ripple>
  </a>
</div>

Full Error

TypeError: Cannot read property 'match' of undefined
    at parseStateRef (http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:4015:22)
    at link (http://localhost:9000/bower_components/angular-ui-router/release/angular-ui-router.js:4100:17)
    at invokeLinkFn (http://localhost:9000/bower_components/angular/angular.js:8258:9)
    at nodeLinkFn (http://localhost:9000/bower_components/angular/angular.js:7768:11)
    at compositeLinkFn (http://localhost:9000/bower_components/angular/angular.js:7117:13)
    at compositeLinkFn (http://localhost:9000/bower_components/angular/angular.js:7120:13)
    at compositeLinkFn (http://localhost:9000/bower_components/angular/angular.js:7120:13)
    at nodeLinkFn (http://localhost:9000/bower_components/angular/angular.js:7763:24)
    at delayedNodeLinkFn (http://localhost:9000/bower_components/angular/angular.js:8016:11)
    at compositeLinkFn (http://localhost:9000/bower_components/angular/angular.js:7117:13) <a ng-attr-ui-sref="{{stateName}}" class="card-header">

Any ideas?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 21 (7 by maintainers)

Most upvoted comments

+1 I simple not understand, why uiRouter check ng-attr-ui-sref? If value is exist then ngAttr build ui-sref otherwise not. Easy? But not, I get this error. So instead of the easy solution I need use ngIf and 2 elements…

instead of:

<a ng-attr-ui-sref="{{::sref}}"></a>

used:

<a ng-if="::sref" ui-sref={{::sref}}></a>
<a ng-if="::!sref"></a>