Monthly Archives: May 2016

$exceptionHandler

  1. – service in module ng

Any uncaught exception in angular expressions is delegated to this service. The default implementation simply delegates to $log.error which logs it into the browser console.

In unit tests, if angular-mocks.js is loaded, this service is overridden by mock $exceptionHandler which aids in testing.

Example:

angular.module('exceptionOverride', []).factory('$exceptionHandler', function() {
  return function(exception, cause) {
    exception.message += ' (caused by "' + cause + '")';
    throw exception;
  };
});

This example will override the normal action of $exceptionHandler, to make angular exceptions fail hard when they happen, instead of just logging to the console.


Note, that code executed in event-listeners (even those registered using jqLite’s on/bind methods) does not delegate exceptions to the$exceptionHandler (unless executed during a digest).If you wish, you can manually delegate exceptions, e.g. try { ... } catch(e) { $exceptionHandler(e); }

Difference between ngBind, ngBindHtml & ngBindTemplate in Angular JS

ng-bind

ngBind is used to replace the text content of the specified HTML element with the value of a given expression. For example if you have an html as follows <b ng-bind="name"></b> and in your controller give a value for name as $scope.name = "John". This will result in <b>John</b>. But you can’t use multiple values to bind in a single html element. For example

$scope.first_name = "John";
$scope.second_name = "D";
<b ng-bind="first_name second_name"></b> 

This will not give the result as <b>John D</b> go here only bind first_name. So for binding multiple values we can use ng-bind-template

ng-bind-template

 $scope.first_name = "John";
 $scope.second_name = "D";

<b ng-bind-template="first_name second_name"></b>

This results in http://stephaniebennettphotography.com/blog <b>John D</b> But you can’t render an html tag in this both. For rendering html template we can use ng-bind-html.

ng-bind-html

$scope.name = "<b>John</b>";
<div ng-bind-html="name"></div>

This will result in follow where can i buy zyvox John instead of showing <b>John</b> . That means it renders the html instead of showing html tag.

Click this link to view example

Error installing packages with NuGet 3.4, 3.4.1

Error installing packages with NuGet 3.4, 3.4.1

Problem:

In NuGet 3.4 and 3.4.1, when using the NuGet add-in, no sources are reported as available and you are unable to add new sources in the configuration window. The result is similar to the image below:

NuGet config with no sources

The NuGet.config file in your %AppData%\NuGet\ folder has accidentally been emptied. To fix this: Close Visual Studio 2015, delete the NuGet.config file in the %AppData%\NuGet\ folder and restart Visual Studio. A new NuGet.Config file will be generated and you will be able to proceed.

Minify files with UglifyJS using GULP.

gulp-uglify

Minify files with UglifyJS.

Install package with NPM and add it to your development dependencies:

npm install --save-dev gulp-uglify

var uglify = require(gulp-uglify);
 
gulp.task(compress, function() {
  return gulp.src(lib/*.js)
    .pipe(uglify())
    .pipe(gulp.dest(dist));
});
  • mangle

    Pass false to skip mangling names.

  • output

    Pass an object if you wish to specify additional output options. The defaults are optimized for best compression.

  • compress

    Pass an object to specify custom compressor options. Pass false to skip compression completely.

  • preserveComments

    A convenience option for options.output.comments. Defaults to preserving no comments.

    • all

      Preserve all comments in code blocks

    • license

      Attempts to preserve comments that likely contain licensing information, even if the comment does not have directives such as @license or /*!.

      Implemented via the uglify-save-license module, this option preserves a comment if one of the following is true:

      1. The comment is in the first line of a file
      2. A regular expression matches the string of the comment. For example: MIT, @license, or Copyright.
      3. There is a comment at the previous line, and it matches 1, 2, or 3.
    • function

      Specify your own comment preservation function. You will be passed the current node and the current comment and are expected to return either true or false.

    • some (deprecated)

      Preserve comments that start with a bang (!) or include a Closure Compiler directive (@preserve, @license,@cc_on). Deprecated in favor of the license option, documented above.

You can also pass the uglify function any of the options listed here to modify UglifyJS’s behavior.

gulp-uglify emits an ‘error’ event if it is unable to minify a specific file. Wherever possible, the PluginError object will contain the following properties:

  • fileName
  • lineNumber
  • message

To handle errors across your entire pipeline, see the gulp documentation.