dcg
dcg

Reputation: 1

Dynamically change function of ng-click based on route

I have an app with many views. On most views I have a toggle-able drawer on the left hand side for navigation. However, on a few views I want the menu to be a back button instead.

I am trying to use ng-click and databinding.

md-button ng-click="{{$scope.current.navBarFunction}}"

to dynamically inject the name, from an attribute navBarFunction in my routes, of the function for ng-click However this doesn't work and I'm unsure how to continue.

.when('/articles/:articleId', {
    title: 'articles.title',
    icon: 'arrow_back',
    navBarFunction: 'backButton()',
    templateUrl: 'views/articles/:articleid.html',
    controller: 'ArticlesArticleidCtrl',
    resolve: {
      loggedin: checkLoggedin
    }
  })

Furthermore, is there anyway to make an if statement in app.js using the current route? That would simplify things.

EDIT 1:

here's more code in our controller:

function navBack(pageID) {
  $location.path( '/' + pageID );
}

function buildToggler(navID) {
  var debounceFn =  $mdUtil.debounce(function(){
        $mdSidenav(navID)
          .toggle()
          .then(function () {
            $log.debug('toggle ' + navID + ' is done');
          });
      },300);
  return debounceFn;
}

$scope.toggleLeft = buildToggler('left');
$scope.navBackUsers = navBack('users');
$scope.navBackArticles = navBack('articles');
$scope.navBackClassrooms = navBack('classrooms');

Upvotes: 0

Views: 415

Answers (1)

charlietfl
charlietfl

Reputation: 171689

Without seeing more of your code it should likely be:

ng-click="current.navBarFunction()"

Not sure why you have () in string value in router or how you are setting this up in directive or controller. Seeing more code would help

Upvotes: 1

Related Questions