定義範圍:{isoNetwork:'= network'},如果父範圍沒有'網絡'屬性,它會自動創建它? 以下PIC是父範圍: 隔離範圍「=」在指令中影響父範圍
這裏是代碼示例(在相同的jsfiddle:http://jsfiddle.net/yougen/mvYrJ/7/):
var app = angular.module('app',[])
app.controller('AppCtrl', function($scope){
$scope.leaveVoicemail = function(number, message, network){
console.log("controller scope: ", $scope);
window.alert("Number: " + number + " said: " + message + ", by network: " + network);
};
});
app.directive('phone', function(){
return {
restrict:'E',
scope:{
isolatedAttributeNumber:'@number',
isoNetwork:'=network',
makeCall:'&'
},
link:function(scope){
scope.networks = ["Verizon", "AT&T", "Sprint"];
scope.isoNetwork = scope.networks[1];
}
};
});
HTML:
<div ng-app="app" ng-controller="AppCtrl">
<phone number="555-1234" network="network" make-call="leaveVoicemail(number, message, network)">
<div>
Number:{{isolatedAttributeNumber}} Network:<select ng-model="isoNetwork" ng-options="net for net in networks"></select>
</div>
Your message:<input type="text" ng-model="voiceMessage"><br>
<button class="btn" ng-click="makeCall({number: isolatedAttributeNumber, message: voiceMessage, network: isoNetwork})">Call Home!</button>
</phone>
</div>
你的小提琴不工作。 – Chandermani
對不起,我已經修復了網址 – jason