function Sandcrawler($scope) {
$scope.location = "Mos Eisley North";
$scope.move = function(newLocation) {
$scope.location = newLocation;
}
}
function Droid($scope) {
$scope.sell = function(newLocation) {
$scope.location = newLocation;
}
}
<div ng-controller="Sandcrawler">
<p>Location: {{location}}</p>
<button ng-click="move('Mos Eisley South')">Move</button>
<div ng-controller="Droid">
<p>Location: {{location}}</p>
<button ng-click="sell('Owen Farm')">Sell</button>
</div>
</div>
function Sandcrawler($scope) {
$scope.obj = {location:"Mos Eisley North"};
}
function Droid($scope) {
$scope.summon = function(newLocation) {
$scope.obj.location = newLocation;
}
}
<div ng-controller="Sandcrawler">
<p>Sandcrawler Location: {{location}}</p>
<div ng-controller="Droid">
<button ng-click="summon('Owen Farm')">
Summon Sandcrawler
</button>
</div>
</div>
function Sandcrawler($scope) {
$scope.location = "Mos Eisley North";
$scope.$on('summon', function(e, newLocation) {
$scope.location = newLocation;
});
}
function Droid($scope) {
$scope.location = "Owen Farm";
$scope.summon = function() {
$scope.$emit('summon', $scope.location);
}
}
<div ng-controller="Sandcrawler">
<p>Sandcrawler Location: {{location}}</p>
<div ng-controller="Droid">
<p>Droid Location: {{location}}</p>
<button ng-click="summon()">Summon Sandcrawler</button>
</div>
</div>
function Sandcrawler($scope) {
$scope.location = "Mos Eisley North";
$scope.recall = function() {
$scope.$broadcast('recall', $scope.location);
}
}
function Droid($scope) {
$scope.location = "Owen Farm";
$scope.$on('recall', function(e, newLocation) {
$scope.location = newLocation;
});
}
<div ng-controller="Sandcrawler">
<p>Sandcrawler Location: {{location}}</p>
<button ng-click="recall()">Recall Droids</button>
<div ng-controller="Droid">
<p>Droid Location: {{location}}</p>
</div>
</div>
function Sandcrawler($scope) {
$scope.$on('requestDroidRecall', function(e) {
$scope.$broadcast('executeDroidRecall');
});
}
function Droid($scope) {
$scope.location = "Owen Farm";
$scope.recallAllDroids = function() {
$scope.$emit('requestDroidRecall');
}
$scope.$on('executeDroidRecall', function() {
$scope.location = "Sandcrawler"
});
}
<div ng-controller="Sandcrawler">
<div ng-controller="Droid">
<h2>R2-D2</h2>
<p>Droid Location: {{location}}</p>
<button ng-click="recallAddDroids()">Recall All Droids</button>
</div>
<div ng-controller="Droid">
<h2>C-3PO</h2>
<p>Droid Location: {{status}}</p>
<button ng-click="recallAddDroids()">Recall All Droids</button>
</div>
</div>
var app = angular.module('myApp', []);
app.factory('instance', function(){
return {};
});
app.controller('MainCtrl', function($scope, instance) {
$scope.change = function() {
instance.name = $scope.test;
};
});
app.controller('sideCtrl', function($scope, instance) {
$scope.add = function() {
$scope.name = instance.name;
};
});
<div ng-controller="MainCtrl">
<input type="text" ng-model="test" />
<div ng-click="change()">click me</div>
</div>
<div ng-controller="sideCtrl">
<div ng-click="add()">my name {{name}}</div>
</div>
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有