<!doctype html>
<html>
<head>
...
<script src="//cdn.manheim.com/assets/js/angular.js"></script>
</head>
...
</html>
<!doctype html>
<html>
<head>
...
<script src="//cdn.manheim.com/assets/js/angular.js"></script>
</head>
<body ng-app>
{{1 + 2}}
</body>
</html>
<body ng-app="clarityApp">...</body>
angular.element(document).ready(function () {
angular.bootstrap(document, ['clarityApp']);
});
<body ng-app>...</body>
<body data-ng-app>...</body>
Custom data attributes are intended to store custom data private to the page or application, for which there are no more appropriate attributes or elements.
~ W3C Specification
<!doctype html> <html> <head> <title>Clarity App</title> <script src="/js/angular.js"></script> </head> <body> <div ng-app="clarityApp">
<!-- contents go here --> </div> <script src="/js/clairtyApp.js"></script> </body> </html>
// js/clarityApp.js
;(function () {
'use strict';
var app = angular.module('clarityApp', []);
}());
app.controller('SearchCtrl', function () {
var _this = this;
this.count = 0;
this.btnPress = function () {
_this.count++;
};
});
<div ng-controller="SearchCtrl as search">
{{search.count}}<br>
<button ng-click="search.btnPress()">++</button>
</div>
app.controller('SearchCtrl', function ($scope) {
// ...
});
app.controller('SearchCtrl', ['$scope', function ($scope) {
// ...
}]);
$scope.$watch(function () {
return _this.count;
}, function (newVal, prevVal) {
if (newVal === prevVal) { return; } // happens during initialization
// do stuff with the newVal
});
$scope.$apply(); // runs $digest
$scope.$on('someEvent', function () { });
$scope.$emit('someEvent'); // crawls scope tree firing the event
$scope.$broadcast('someEvent'); // tells everyone regardless of tree
app.service('TwitterService', function () {
var _this = this;
this.results = [];
this.search = function (query) {
};
});
app.controller('SearchCtrl', function (TwitterService) {
var _this = this;
this.query = '';
this.btnSearch = function () {
TwitterService.search(_this.query);
};
});
app.service('TwitterService', function ($http) {
var _this = this;
this.results = [];
this.search = function (query) {
return $http({
url: 'https://api.twitter.com/1.1/search/tweets.json',
params: { q: query }
}).then(function (resp) {
_this.results = resp.statuses; // array of statuses
return resp.statuses;
});
};
});
app.controller('ResultsCtrl', function ($scope, TwitterService) {
var _this = this;
this.results = [];
$scope.$watch(function () {
return TwitterService. results;
}, function (newVal, prevVal) {
if (newVal === prevVal) { return; }
_this.results = newVal;
});
});
<body ng-app></body>
<body ng-app="clarityApp"></body>
<body data-ng-app></body>
<body data-ng-app="clarityApp"></body>
<div ng-controller="ResultsCtrl as results">
<ul>
<li class="media" ng-repeat="status in results.results">
<div class="img">
<img src="{{status.user.profile_image_url}}" width="60" height="60">
</div>
<div class="content">
<h2>{{status.user.name}} {{"@" + status.user.screen_name}}</h2>
<p>{{status.text}}</p>
</div>
</li>
</ul>
</div>
<mui-ymmt mui-year="2014" mui-make="Tesla" mui-model="Model S"/>
<mui-media mui-image="//placekitten.com/60/60">
<h2>Marvin the Cat</h2>
<p>This is a very special kitty!</p>
</mui-media>
{{ 3.2 | currency }} // $3.20
{{ '1388123412323' | date }} // Dec 27, 2013
{{ 'Hello, world!' | uppercase }} // HELLO, WORLD!
{{ 'Hello, world!' | lowercase }} // hello, world!
{{ '1388123412323' | date | uppercase }} // DEC 27, 2013
app.filter('userLink', function () {
return function (str) {
if (typeof str !== 'string') {
str = String(str);
}
return str.replace(/@([a-zA-Z0-9_]+)/gi,
'<a href="http://twitter.com/$1" target="_blank" class="tAt">@$1</a>'
);
};
});
app.controller('SearchCtrl', ['$scope', function ($scope) {
// ...
}]);
<!doctype html>
<html>
<head>
<script src="/js/angular.js"></script>
</head>
<body>
<script src="/js/app.js"></script>
</body>
</html>