index.html
<!DOCTYPE html>
<html>
<head>
<title>Creating Custom Directives</title>
</head>
<body ng-app="myApp">
<div ng-controller="main">
<my-todo list="todo" title="Angular To-do"></my-todo>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<script src="script.js"></script>
</body>
</html>
todo.tpl.html
<h1>{{title}}</h1>
<div ng-repeat="todo in list">
<input type="checkbox" ng-model="todo.completed"> {{ todo.name }}
</div>
script.js
var app = angular.module('myApp', []);
app.directive('myTodo', function() {
return {
restrict: 'EA',
templateUrl: 'todo.tpl.html',
scope: {
list: '=',
title: '@'
}
};
});
app.controller('main', function($scope){
$scope.todo = [
{name: 'Create a custom directive', completed: true},
{name: 'Learn about restrict', completed: true},
{name: 'Master scopes', completed: false}
];
});
In the above snippet, I created a custom directive called 'my-todo', now I created a template in a different file named 'todo.tpl.html'. When I tried to load the file I get the following errors:-
Failed to load file:///Users/sumo/Desktop/Tejas/GitHub/furry-happiness/customDirective/todo.tpl.html: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
angular.js:14800 Error: [$compile:tpload] http://errors.angularjs.org/1.6.9/$compile/tpload?p0=todo.tpl.html&p1=-1&p2=
Can someone provide the reading links and proper documentation links to know more about templates can be helpful?