Pages

Friday, September 30, 2016

Angular Js- Using minified version of Controller,filter js files

Using minifed version of controller JS Files

Here we will use a controller as an example same can be used for Filters

One important thing to note when we isolate controller from our HTML file is during its minification.
The minification also minifies variable in controller and $scope,$http,$filter may become variables a,b,c which are not recognized by angular see the minified version of above controller.js is as follows

controller.js

 angular.module('myApp',[]).controller('myCtrl',function($scope){  
 $scope.names=[  
 {name:'Gaurav',country:'India'},  
 {name:'Mike',country:'USA'},  
 {name:'Steve',country:'Denmark'}  
 ];  
 });  

controller.min.js

 angular.module("myApp",[]).controller("myCtrl",function(n){n.names=[{name:"Gaurav",country:"India"},{name:"Mike",country:"USA"},{name:"Steve",country:"Denmark"}]});  

Here $scope becomes n and this will not be recognized by angular js.To over come this problem use code controller code in controller.js as

controller.js

 angular.module('myApp',[]).controller('myCtrl',["$scope",myCtrl]);  
 function myCtrl($scope){  
 $scope.names=[  
 {name:'Gaurav',country:'India'},  
 {name:'Mike',country:'USA'},  
 {name:'Steve',country:'Denmark'}  
 ];  
 };  

In this we isolate the Controller function but we also tell the module that the first parameter of this function will be "$scope"

The Minified version of this file is

controller.min.js

 function myCtrl(n){n.names=[{name:"Gaurav",country:"India"},{name:"Mike",country:"USA"},{name:"Steve",country:"Denmark"}]}angular.module("myApp",[]).controller("myCtrl",["$scope",myCtrl]);  

Above file also changes the parameter $scope of the function to "n" but when final call is made to function the first parameter is sent as $scope

Monday, September 26, 2016

open cart 2.3 change Theme

To change in open cart 2.3

1. Go to Admin=>Extensions(main menu)=>Extensions(sub menu)




2. Select Themes as Extension Type

3. Click on Edit Action in Your store(blue button in above image) and select your theme directory


That's it

Saturday, September 24, 2016

Angular Js- Use a filter in expression with javascript addition operator

Recently in one of my Projects I was stuck up in an issue regarding filters

Here is My Custom Filter

       app.filter('alterCap',function()   
       {  
         return function(x)   
         {  
           var i, c, txt = "";  
           for (i = 0; i < x.length; i++) {  
             c = x[i];  
             if (i % 2 == 0) {  
               c = c.toUpperCase();  
             }  
             txt += c;  
           }  
           return txt;  
         };  
       });  

I am trying to use this filter in my HTML as

 {{ x.country|alterCap + ":" + x.capital|alterCap }}  

But this didn't worked out so I had to use filter in my controller.Here is how I did the same

 app.controller("myCtrl",function($scope,$filter){  
         $scope.capitals = [  
         {country:'India',capital:'Delhi'},  
         {country:'Sri Lanka',capital:'Colombo'},  
         {country:'Afganistan',capital:'Kabul'},  
         {country:'Bhutan',capital:'Norway'},  
         {country:'Nepal',capital:'Thimphu'},  
         {country:'Japan',capital:'Tokyo'},  
         {country:'China',capital:'Beijing'},  
         {country:'Russia',capital:'Moscow'},  
         {country:'USA',capital:'Washington, D.C.'}  
         ];  
         $scope.applyAlterCap = function(movie){  
           return $filter('alterCap')(movie);  
         };  
       });  

And then I used this in my Html as follows

 <p>Using Custom Filter with addition operator inside expression</p>  
     <ul>  
       <li ng-repeat="x in capitals | orderBy:'capital'">  
         {{ applyAlterCap(x.country) + ":" + x.capital }}  
       </li>  
     </ul>  

Tuesday, September 20, 2016

Ubuntu boots into command line after update

I recently faced this issue after updating to Ubuntu 15.10 and was looking for solutions until this one worked for me

Enter into recovery mode from grub and run the following  command

sudo dpkg --configure -a