Friday, December 25, 2015

Deregister an AngularJS $watch Expression

As you know $watch registers a listener callback that is executed whenever the watch expression changes.

The $watch function returns a deregister function. Calling this deregister function will deregister the $watch expression

Here is an example on registering and deregistering the $watch expression

//registering the $watch listener. It returns a deregister function
var deregister = $scope.$watch('name', function(newValue, oldValue) {
  //code here
});

//calling the deregister function
deregister();

AngularJS Cancel $timeout

$timeout returns a promise. This promise is resolved when delay is passed and the timeout function is executed.

To cancel the timeout request, call $timeout.cancel(promise).

Here is an example on how to cancel the $timeout

//setting timeout and storing the return value in a local variable
var promise = $timeout(function () {
    //code to be executed after 50 milliseconds
}, 50);

//Cancelling the above timeout by passing the promise

$timeout.cancel(promise)

Update NPM for Visual Studio 2015

Below are the steps to update NPM for Visual Studio:
  • Download latest Node package (which includes NPM) from the below link

o   In the above link click on the latest version (currently it is latest-v5.x)
o   From the latest version download the latest 64 bit (node-v5.3.0-x64.msi) or 32 bit msi(node-v5.3.0-x86.msi)
  • Run the msi to install the Node & NPM
  • Once Node and NPM is installed, open the VS2015 Developer Command Prompt
  • Type npm to find the path where npm is installed

  • As you can see npm location on my laptop. We need to specify this path in Visual Studio
  • Open Visual Studio and go to Tools > Options > Projects and Solutions > External Web Tools
 
  • Add the path of npm in Visual Studio (remove the last part of the path "node_modules/npm"
  • With the above steps your npm is updated in the global path and the correct path is set in Visual Studio.
In future if you want to update npm you just need run the below command


npm install npm stable -g