我試圖獲得一個自定義指令工作在角度,部分遵循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
在服務器上運行您的代碼。它正在拋出異源請求錯誤。 –
我已經回答。這有助於你理解問題並推薦解決方案嗎? –