How is AngularJS different from jQuery

While Angular 1 was a framework, Angular 2 is a platform. (ref) To developers, Angular2 provides some features beyond showing data on screen. For example, using angular2 cli tool can help you “pre-compile” your code and generate necessary javascript code (tree-shaking) to shrink the download size down to 35Kish. Angular2 emulated Shadow DOM. (ref) This … Read more

AngularJS access parent scope from child controller

If your HTML is like below you could do something like this: <div ng-controller=”ParentCtrl”> <div ng-controller=”ChildCtrl”> </div> </div> Then you can access the parent scope as follows function ParentCtrl($scope) { $scope.cities = [“NY”, “Amsterdam”, “Barcelona”]; } function ChildCtrl($scope) { $scope.parentcities = $scope.$parent.cities; } If you want to access a parent controller from your view you … Read more

Difference between the ‘controller’, ‘link’ and ‘compile’ functions when defining a directive

I’m going to expand your question a bit and also include the compile function. compile function – use for template DOM manipulation (i.e., manipulation of tElement = template element), hence manipulations that apply to all DOM clones of the template associated with the directive. (If you also need a link function (or pre and post … Read more

SyntaxError: Unexpected token o in JSON at position 1

The JSON you posted looks fine, however in your code, it is most likely not a JSON string anymore, but already a JavaScript object. This means, no more parsing is necessary. You can test this yourself, e.g. in Chrome’s console: new Object().toString() // “[object Object]” JSON.parse(new Object()) // Uncaught SyntaxError: Unexpected token o in JSON … Read more

How can I test an AngularJS service from the console?

TLDR: In one line the command you are looking for: angular.element(document.body).injector().get(‘serviceName’) Deep dive AngularJS uses Dependency Injection (DI) to inject services/factories into your components,directives and other services. So what you need to do to get a service is to get the injector of AngularJS first (the injector is responsible for wiring up all the dependencies … Read more

How to dynamically change header based on AngularJS partial view?

I just discovered a nice way to set your page title if you’re using routing: JavaScript: var myApp = angular.module(‘myApp’, [‘ngResource’]) myApp.config( [‘$routeProvider’, function($routeProvider) { $routeProvider.when(“https://stackoverflow.com/”, { title: ‘Home’, templateUrl: ‘/Assets/Views/Home.html’, controller: ‘HomeController’ }); $routeProvider.when(‘/Product/:id’, { title: ‘Product’, templateUrl: ‘/Assets/Views/Product.html’, controller: ‘ProductController’ }); }]); myApp.run([‘$rootScope’, function($rootScope) { $rootScope.$on(‘$routeChangeSuccess’, function (event, current, previous) { $rootScope.title = … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)