1
我想知道爲什麼以下工作不如我預期的那樣工作。我認爲這將表明這一點: 用戶:雅各布Jenkov用戶:李四AngularJS自定義指令 - 隔離範圍問題
然而,這表明這一點:
用戶:用戶:
HTML:
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="[email protected]" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js" data-semver="1.5.11"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MyController as $ctrl">
<userinfo user="jakob"></userinfo>
<userinfo user="john"></userinfo>
</body>
</html>
JAVASCRIPT:
var myapp = angular.module('plunker', []);
myapp.directive('userinfo', function() {
var directive = {};
directive.restrict = 'E';
directive.template = "User : <b>{{user.firstName}}</b> <b>{{user.lastName}}</b>";
directive.scope = {
user : "="
}
return directive;
});
myapp.controller("MyController", function() {
var $ctrl = this;
$ctrl.jakob = {};
$ctrl.jakob.firstName = "Jakob";
$ctrl.jakob.lastName = "Jenkov";
$ctrl.john = {};
$ctrl.john.firstName = "John";
$ctrl.john.lastName = "Doe";
});