How can I define my controller using TypeScript?

There are 2 different ways to tackle this: still using $scope using controllerAs (recommended) using $scope class CustomCtrl{ static $inject = [‘$scope’, ‘$http’, ‘$templateCache’]; constructor ( private $scope, private $http, private $templateCache ){ $scope.search = this.search; } private search (search) { debugger; var Search = { AccountId: search.AccountId, checkActiveOnly: search.checkActiveOnly, checkParentsOnly: search.checkParentsOnly, listCustomerType: search.listCustomerType }; … Read more

How to generate url encoded anchor links with AngularJS?

You can use the native encodeURIComponent in javascript. Also, you can make it into a string filter to utilize it. Here is the example of making escape filter. js: var app = angular.module(‘app’, []); app.filter(‘escape’, function() { return window.encodeURIComponent; }); html: <a ng-href=”#/search?query={{address | escape}}”> (updated: adapting to Karlies’ answer which uses ng-href instead of … Read more

AngularJS – Passing data between pages

You need to create a service to be able to share data between controllers. app.factory(‘myService’, function() { var savedData = {} function set(data) { savedData = data; } function get() { return savedData; } return { set: set, get: get } }); In your controller A: myService.set(yourSharedData); In your controller B: $scope.desiredLocation = myService.get(); Remember … Read more

How to format a date using ng-model?

Use custom validation of forms http://docs.angularjs.org/guide/forms Demo: http://plnkr.co/edit/NzeauIDVHlgeb6qF75hX?p=preview Directive using formaters and parsers and MomentJS ) angModule.directive(‘moDateInput’, function ($window) { return { require:’^ngModel’, restrict:’A’, link:function (scope, elm, attrs, ctrl) { var moment = $window.moment; var dateFormat = attrs.moDateInput; attrs.$observe(‘moDateInput’, function (newValue) { if (dateFormat == newValue || !ctrl.$modelValue) return; dateFormat = newValue; ctrl.$modelValue = new … Read more

How to select an element by classname using jqLite?

Essentially, and as-noted by @kevin-b: // find(‘#id’) angular.element(document.querySelector(‘#id’)) //find(‘.classname’), assumes you already have the starting elem to search from angular.element(elem.querySelector(‘.classname’)) Note: If you’re looking to do this from your controllers you may want to have a look at the “Using Controllers Correctly” section in the developers guide and refactor your presentation logic into appropriate directives … Read more

AngularJS $http, CORS and http authentication

No you don’t have to put credentials, You have to put headers on client side eg: $http({ url: ‘url of service’, method: “POST”, data: {test : name }, withCredentials: true, headers: { ‘Content-Type’: ‘application/json; charset=utf-8’ } }); And and on server side you have to put headers to this is example for nodejs: /** * … Read more