<div class="block-views-markup first">
<div class="view">
<div class="views-row views-row-first">
<div class="node content">
<div class="field field-recipe-title">
This is a Recipe's title
</div>
<div class="field field-recipe-body">
This is body content of recipe.
</div>
</div>
...
<article class="recipe">
<div class="heading--primary">{{ recipe.title }}</div>
<div class="bodyText--light">{{ recipe.body }}</div>
</article>
Web component:
<recipe></recipe>
header('Access-Control-Allow-Origin: *');
D8 CORS contrib module
<html ng-app="clientTheme">
<body>
<div ng-contoller="FormCtrl">
Click to show form!
</div>
</body>
</html>
//app.js
var theme = angular.module('clientTheme', []);
theme.controller('FormCtrl', function($scope) {
$scope.showForm = false;
});
[{
"title": "Burrito",
"body": "Very yum..."
}]
// app.js
theme.controller('recipeCtrl',
function($scope) {
$scope.recipe.title = 'Burrito';
$scope.recipe.body = 'Very yum...';
});
<div ng-controller="recipeCtrl">
{{ recipe.title }}
{{ recipe.body }}
</div>
{{ recipe.meNoUnderstand }}
Burrito
[{
"id" : 1,
"name": "Tacos de Guerrero"
},
{
"id" : 2,
"name": "Burritos de Jalisco"
},
... more recipes
]
[{
"id" : 1,
"name": "Tacos de Guerrero"
},
{
"id" : 2,
"name": "Burritos de Jalisco"
},
... more recipes
]
// defined by recipeCtrl
$scope.recipes
= $http.get('recipes.json');
<div ng-controller="recipesCtrl">
{{ recipes }}
</div>
<ul ng-controller="recipesCtrl">
<li ng-repeat="recipe in recipes">
{{recipe.id}} - {{recipe.name}}
</li>
</ul>
...
http://plnkr.co/edit/a7wVJBTraXKmmaObDJXk
theme.factory('recipeService', function($http) {
return {
getRecipes: function(callback) {
$http.get('recipes.json').success(callback);
}
}
});
theme.controller('recipesCtrl', function($scope, recipeService) {
recipeService.getRecipes(function(data) {
$scope.recipe = data;
});
});
http://plnkr.co/edit/a7wVJBTraXKmmaObDJXk
theme.config(function($httpProvider){
$httpProvider.defaults.headers.common['Accept'] = 'application/hal+json';
// delete $httpProvider.defaults.headers.common['X-Requested-With'];
});
theme.factory('nodeService', function($http) {
return {
getNode: function(nid, callback) {
$http.get('http://mydrupalsite.com/node/' + nid).success(callback);
}
}
}
http://plnkr.co/edit/2y2pnDs9mHalL5MJqmVe
<head>
<script src="js/angular.js"></script>
<script src="js/angular-route.js"></script>
<script src="app.js"></script>
</head>
<body>
<a href="/">Home</a>
<a href="/contact">Contact</a>
<a href="/about">About</a>
// ng-view is like $content in page.tpl
<div ng-view></div>
</body>
var theme = angular.module('clientTheme', ['ngRoute']);
clientTheme.config(function($routeProvider) {
$routeProvider
.when('/', {
templateUrl : 'templates/home.html',
controller : 'mainController'
})
.when('/contact', {
templateUrl : 'templates/contact.html',
controller : 'contactController'
});
.when('/about-us', {
templateUrl : 'templates/about.html',
controller : 'aboutController'
});
});
Node detail page: node/1 vs. node/2
clientTheme.config(function($routeProvider) {
$routeProvider
.when("/node/:nid", {
templateUrl : "node.html" ,
controller : "NodeCtrl"
});
});
app.controller("NodeCtrl", function($scope, $routeParams) {
$scope.nid = $routeParams.nid;
});
http://plnkr.co/edit/pJCzB8vYfN6W23MsHQNr
app.factory('dftService', function($http) {
return {
getNode: function(nid, callback) {
$http.get('http://mydrupalsite.com/node/' + nid)
.success(callback);
}
}
});
Controller
app.controller('NodeCtrl',
function($scope, dftService, $routeParams) {
dftService.getNode($routeParams.nid, function(data) {
$scope.node = data;
});
});
http://plnkr.co/edit/3ekxhyl9kZdVIwVBRT40
ng-repeat="recipe in recipes | filter:{field_tags:searchTermText}"