5/3.In the installApp directive, add a fourth option


#1

app.directive ('installApp', function() {
	return {
    restrict : 'E',
    scope : {},
    templateUrl : 'js/directives/installApp.html',
    link: function(scope, element, attrs) { 
  scope.buttonText = "Install", 
  scope.installed = false, 

  scope.download = function() { 
    element.toggleClass('btn-active'); 
    if(scope.installed) { 
      scope.buttonText = "Install"; 
      scope.installed = false; 
    } else { 
      scope.buttonText = "Uninstall"; 
      scope.installed = true; 
    } 
  } 
}};  
});

I don't know how to implement the function on the fourth option named link, what should I do? I think that's a problem of my knowledge about Javascript's nomenclature... Who could give me a explanation of the answer? Thanks you very much!


#2

I think there is a mistake in the instructions, I got it to work as below.

app.directive('installApp', function() { 
  return { 
    restrict: 'E', 
    scope: {}, 
    templateUrl: 'js/directives/installApp.html',
    link: function(scope, element, attrs) {
      scope.buttonText = "Install"; 
  		scope.installed = false;
      
      scope.download = function() { 
        element.toggleClass('btn-active'); 
        if(scope.installed) { 
          scope.buttonText = "Install"; 
          scope.installed = false; 
        } else { 
          scope.buttonText = "Uninstall"; 
          scope.installed = true; 
        } 
      };      
    }
	};
});

Notice that I have semi colons rather than commas on the end of some of the lines, if I understand correctly the commas are a mistake as they would be used if this was for object attributes however it is a function so semi colons on the end of those lines is actually correct.


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.