我正在搞亂關於指令的Angular文檔,並預計這會起作用:隔離範圍「@」如何工作?
我想我可以使用「@」來獲取info屬性,但它似乎不起作用,我期待要顯示info.name和info.address表達式,但它們是空白的。
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example - example-example16-production</title>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.5.0-rc.1/angular.min.js"></script>
<script src="app.js"></script>
</head>
<body ng-app="docsIsolateScopeDirective">
<div ng-controller="Controller">
<my-customer info="naomi"></my-customer>
<hr>
<my-customer info="igor"></my-customer>
</div>
</body>
</html>
app.js
(function(angular) {
'use strict';
angular.module('docsIsolateScopeDirective', [])
.controller('Controller', ['$scope', function($scope) {
$scope.naomi = { name: 'Naomi', address: '1600 Amphitheatre' };
$scope.igor = { name: 'Igor', address: '123 Somewhere' };
}])
.directive('myCustomer', function() {
return {
restrict: 'E',
scope: {
info: '@'
},
templateUrl: 'my-customer-iso.html'
};
});
})(window.angular);
我-客戶iso.html
Name: {{info.name}} Address: {{info.address}}
沒有。名稱屬性* 「它似乎不起作用」*並不能解釋它實際在做什麼或你期望它做什麼。 – charlietfl
添加說明 – WinchenzoMagnifico
似乎是對文檔的誤解。檢查瀏覽器開發工具中的範圍值究竟是什麼 – charlietfl