0
基本上按鈕點擊將調用MyController
的ShowHide()
函數,並且如果$scope.IsVisible==false
,則複製該值。
但是,這裏指的是$scope
的formController
。 console.log的輸出證明了這一點,雖然這是我期望做的事情,但有人可以解釋我是怎麼做到的?那是因爲Javascript原型嗎?
<div ng-app="MyApp" ng-controller="MyController">
<div ng-controller="formController">
<div ng-bind="broker.info"></div>
<div ng-show="IsVisible">Some content to be hide</div>
<button ng-click="ShowHide()">ok</button>
</div>
</div>
腳本:
var app = angular.module('MyApp', []);
var old = <?=json_encode($broker)?>;
app.controller('formController',function ($scope) {
$scope.broker = angular.copy(old);
});
app.controller('MyController', function ($scope) {
$scope.IsVisible = false;
$scope.ShowHide = function() {
//If DIV is visible it will be hidden and vice versa.
$scope.IsVisible = $scope.IsVisible ? false : true;
if($scope.IsVisible==false) {
this.broker = angular.copy(old);
console.log(this);
console.log($scope);
}
}
});
截圖:你的問題的
的可能的複製[什麼是範圍原型在AngularJS /原型繼承?的細微差別(http://stackoverflow.com/questions/14049480/what-are-the-nuances-of-scope-prototypal -prototypical繼承功能於angularjs) – Claies