Installapp I 5/8


#1

I put this code to the text editor but something is wrong.

app.directive('installApp', function() {
return {
restrict: 'E',
scope: { },
templateUrl: 'js/directives/installApp.html'
};
});


#2

@blogninja05675,
Try by removing the space character from your =empty= scope object
like

app.directive('installApp', function() { 
 return { 
 restrict: 'E', 
 scope: {}, 
 templateUrl: 'js/directives/installApp.html'
 }; 
});

#3

This is the code-
app.directive('installApp', function() {
return {
restrict: 'E',

scope: {info: '='}, 

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;
}
};
}};
});
On compiling showing "expected an assignment or function call and instead saw an expression" error.
I don't understand where is the problem....Pls Help.


#4

Hello!
My code like yours, but it doesn't work too, and with no error message I don't know what is the problem


#5

my code is:
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 cant pass this step 5.3/8...
I cant find the problem in my code...
to the 18th line of code..."expected an assigment or fuction call and instead saw an expression", "missing semicolon"..

Any chance to have some help here?


#6

@thalia1983
With this the installApp directive will create an object

app.directive('installApp', function() { return {}; });

( take notice of the semi-colon-; at the end-of-a-return )

The object will have following property-key's

app.directive('installApp', function() { return {
    restrict: "E",
       scope: {},   <== associated-Value of scope  is an object
 templateURL: 'js/directives/installApp.html',
        link: function(scope, element, attrs) { }
}; });

The link property with property-key link has an associated anonymous Function Value which is thus a Method, which takes 3 parameter

Have a look at
https://discuss.codecademy.com/t/5-8-install-app-1/11316?u=leonhard.wettengmx.n


#7

Replace the code
scope.buttonText = "Install",
scope.installed = false,

of
scope.buttonText = "Install";
scope.installed = false;

Place ; instead of ,


#8

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; 
    };
    };
  }
  };
});

#9

Hi All,

Please help I am also facing same issues, PFA.

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; 
       }	
  }
}

};
});


#10

Solved, I have resolved above error :slight_smile:

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; 
       }	
  };
}

};
});


#11

I have the same issue, I just reported it as a bug


#12

Replace "," with ";" after "install" and false.
That should fix this problem.


#13

For the future:

This works:

app.directive('installApp',function()
{
  return {
    restrict:'E',
    scope:
    {},
    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; 
    			}
  		};
    },
    templateUrl:'js/directives/installApp.html'
  };
});

#14

Thank you so much... i read all the post but finally your post worked out well..
just by replacing templateUrl with link attribute..it worked fine.

I guess when we submit the code there is some issue with parser which codecademy is providing


#15

I attach my screenshot. THe message it says to me is "Did you add the function to installApp.js?". I don't see any difference with solutions of people that claim their solution works.

Here is the file


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

Can anyone help me with that? Anyone can see anything wrong in my solution?

Thank


#16

@microcoder41016 i was also facing the same problem and your code is absolutely correct just put the link option before the template option.


#17

Please review my code below :slight_smile:
app.directive('installApp', function(){
return{
restrict:'E',
scope:{},

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;
}
};
},
templateUrl:'js/directives/installApp.html'
};
});

It still gives error as 'Did you add the function in installApp.js ?'


#18

@aditijoshi your code is correct just write it again or copy the code from the codmakr's post and it will work. The two codes are the same but it worked for me doing this.


#19

Thanks, for your help :slight_smile:


#20

thanks for this- worked a treat.