Created by Christian Köberl
{{ }}
$scope
and services injected. Creates and changes the model.directive
<my-tabs>
<my-tab title="This is tab">
<p>A tab content</p>
</my-tab>
<my-tab title="Another tab">
<p>Some more tabby stuff</p>
</my-tab>
</my-tabs>
module.component('my-comp', {
template: '<div>{{ param1 }}</div>',
templateUrl: 'template.html',
require: { // controllers of other components
directParent: '^parentComponent',
anyParent: '^^parentComponent'
},
bindings: {
param1: '<', // one-way binding
param2: '=', // two-way binding
onEvent: '&' // callbacks/events
},
controller: function ComponentController() {
this.onEvent(this.param1);
this.directParent.lala(this.param2);
}
});
<my-panel title="This is the title">
This is the content
<my-panel>
<span ng-bind="[expression]">
<input data-ng-model="[expression]">
<ng-form>...</ng-form>
<span class="ng-click: [expression]">
<!-- directive:my-directive -->
ngModel
<span>{{ expression }}</span>
<span ng-bind="expression"></span>
27 + 15 ⇒ 42
person.name
⇒ get person object form $scope and use name attributemyFunction()
⇒ get result of call to myFunction on $scope<button ng-click="doSomething()">Click Me</button>
<input type="checkbox" ng-model="confirmed" ng-change="change()" />
ng-show/ng-hide
- set display to noneng-if
- remove element from DOM<div class="error" ng-if="error">{{error}}<div>
module.value('clientId', clientId)
module.factory('client', function clientFactory(clientId) {
var client = {};
return client;
})
module.service('client', function Client(clientId) {
this.clientId = clientId;
})
backendUrl
"https://jsontest-derkoe.appspot.com/?service=date"backendUrl
via GET (using $http)angular.module('my-app', ['ngAnimate'])
describe('Controller: WeatherCtrl', function() {
it('calls weatherService to get weather', function() {
inject(function($rootScope, $controller) {
var weather = { temp : { current : 10 } },
weatherService = {
getWeather : function() {
return weather;
}
},
scope = $rootScope.$new;
$controller('WeatherCtrl', {
$scope : scope,
weatherService : weatherService
});
expect(scope.weather).toBe(weather);
});
});
});
describe('Service: weatherService', function() {
var url = 'http://api.openweathermap.org/data/2.5/weather?q=Salzburg,at&units=metric&callback=JSON_CALLBACK';
var $httpBackend, weatherService;
beforeEach(inject(function($injector) {
$httpBackend = $injector.get('$httpBackend');
weatherService = $injector.get('weatherService');
}));
it('maps the correct current temp', function() {
$httpBackend.whenJSONP(url).respond({
main : {
temp : 10
}
});
$httpBackend.expectJSONP(url);
var weather = weatherService.getWeather();
$httpBackend.flush();
expect(weather.temp.current).toBe(10);
});
});
describe('Filter: temp', function() {
var tempFilter;
beforeEach(inject(function($filter) {
tempFilter = $filter('temp');
}));
it('adds °C', function() {
expect(tempFilter(3)).toBe('3.0°C');
});
it('handles precision correctly', function() {
expect(tempFilter(3, 10)).toBe('3.0000000000°C');
});
it('handles non-numbers', function() {
expect(tempFilter('a')).toBe('°C');
expect(tempFilter({})).toBe('°C');
});
});
{{ data.name }}
ng-model="data.name"
ng-click="save()"
ng-model="name"
@Component({
selector: 'todos',
templateUrl: 'todos.html'
})
class Todos {
todos = ["Things to do", "Another thing"];
addTodo(todo) {
this.todos.push(todo);
}
}
<form (submit)="addTodo(todotext.value)">
<input placeholder="Enter your todo" #todotext>
<button type="submit">Add Todo</button>
</form>
<ul><li *ngFor="#todo of todos">{{ todo }}</li></ul>