This is part five of my look into AngularJS.
- AngularJS Intro and Setup
- AngularJS and Modernizr
- AngularJS and jQueryUI DatePicker
- AngularJS with TextArea and Scroll To
- AngularJS and Javascript Tips
- Coming soon…
AngularJS
AngularJS functions that can be used instead of using typeof(). For instance angular.isUndefined() can be used instead of doing typeof(a) === 'undefined'. Below is a list of some these functions which can be found in the AngularJS documentation.
1
2
3
4
5
6
7
8
9
|
angular.isArray
angular.isDate
angular.isDefined
angular.isElement
angular.isFunction
angular.isNumber
angular.isObject
angular.isString
angular.isUndefined
|
Strict Contextual Escaping (sce)
In AngularJS, to send unicode characters from Javascript to HTML you need to use angular-sanitize.
Include the AngularJS service $sce in the controllers.js.
1
2
3
4
5
6
7
|
var mycontroller = angular.module('myApp.controllers', []);
mycontroller.controller('MainController', [ '$scope', '$sce', function($scope, $sce) {
...
var uniString = '©'; //& # 169;
$scope.htmltext = $sce.trustAsHtml(uniString);
...
}]);
|
Then in HTML:
1 |
<span ng-bind-html="htmltext"></span>
|
For more information on $sce head over and read the AngularJS documentation on $sce.
For more on ngSanitize read: Using ngSanitize to render HTML strings in Angular
Javascript
The equal:
A single = is an assignment
e.g.
var a = b;
A double == is an equal
e.g.
if( 1 == 2 ) // this will be false
A triple === is a strict equal to
e.g.
1
2
3
|
if( 1 === 1 ) // guarantees the correct result
if( typeof(c) === 'undefined') // this will return true, we have not defined c
|
Two references that might be helpful:
- JavaScript Triple Equals Operator vs Double Equals Operator ( === vs == )
- Triple (3) Equal Signs [duplicate]
More examples can be found on GitHub: True, False and Equal in JS.