From c621068b96ba769e5cbca863175c69f9ffe47a5f Mon Sep 17 00:00:00 2001 From: Hugo Torzuoli Date: Tue, 13 Feb 2018 00:06:00 +0100 Subject: [PATCH] Update angularjs.md Lint HTML & JS Code --- angularjs.md | 63 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/angularjs.md b/angularjs.md index de500bde7..c0285555f 100644 --- a/angularjs.md +++ b/angularjs.md @@ -2,35 +2,40 @@ title: Angular.js category: JavaScript libraries --- - - +```html +     +``` ### Lists (ng-repeat) - +```html +     +``` ### Model (ng-model) +```html +     +``` ### Defining a module - - App = angular.module('myApp', []); +```js +    App = angular.module('myApp', []); App.controller('MyListCtrl', function ($scope) { $scope.phones = [ ... ]; - }); +    }); +``` ### Controller with protection from minification - - App.controller('Name', [ +```js +    App.controller('Name', [ '$scope', '$http', function ($scope, $http) { @@ -41,44 +46,48 @@ category: JavaScript libraries '$scope' '$http' ($scope, $http) -> - ] +    ] +``` ### Service - - App.service('NameService', function($http){ +```js +    App.service('NameService', function($http){ return { get: function(){ return $http.get(url); } } - }); - +    }); +``` In controller you call with parameter and will use promises to return data from server. - App.controller('controllerName', +```js +    App.controller('controllerName', function(NameService){ NameService.get() .then(function(){}) - }) +    }) +``` ### Directive - - App.directive('name', function(){ +```js +    App.directive('name', function(){ return { template: '

Hello

' } - }); +    }); +``` In HTML will use `` to render your template `

Hello

` ### HTTP - - App.controller('PhoneListCtrl', function ($scope, $http) { - $http.get('/data.json').success(function (data) { - $scope.phones = data; - }) - }); - +```js + App.controller('PhoneListCtrl', function ($scope, $http) { + $http.get('/data.json').success(function (data) { + $scope.phones = data; + }) +    }); +``` References: * https://github.com/angular/angular-seed