我试图获得一个自定义指令工作在角度,部分遵循official document。自定义指令演示
在Chrome中,我只看到一个空白页。
F12显示了这个错误:
XMLHttpRequest cannot load file:///home/jeff/workspace/angularjs-intro/playground/my-customer.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
这是我走到这一步:
(function() {
var app = angular.module('docsRestrictDirective', []);
app.controller('Controller', function() {
});
app.directive('myCustomer', function() {
return {
restrict: 'E',
templateUrl: 'my-customer.html'
};
});
})();
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-example14-production</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.min.js"></script>
<script src="script.js"></script>
</head>
<body ng-app="docsRestrictDirective">
<div ng-controller="Controller">
<my-customer></my-customer>
</div>
</body>
</html>
而且我-customer.html
Name: {{customer.name}} Address: {{customer.address}}
任何帮助表示赞赏。
您需要周围的我的customer.HTML一个div。我也没有看到任何数据被传递给指令。 – iamrelos
在服务器上运行您的代码。它正在抛出异源请求错误。 –
我已经回答。这有助于你理解问题并推荐解决方案吗? –