我上AngularJs應用程序的工作,我使用的是指令和控制範圍子頭/尾爲空
指令負責獲取心滿意足的列表,然後選擇國家城市的新列表產生
現在我想進行編輯的場景,所以我的狀態和所選擇的城市,但我想將其設置爲指令範圍
controller.js
if($scope.$$childHead && $scope.$$childHead.changeState){
$scope.$$childHead.state=$rootScope.state;
$scope.$$childHead.changeState($rootScope.state)
$scope.$$childHead.city=$rootScope.city;
}
個
directive.js
app.directive('w34UsAddress', function ($http,$rootScope) {
return {
restrict: "A",
scope: {
state: '=',
city: '=',
changeState:'&'
},
templateUrl:'templates/usAddress.html' ,
link: function (scope,elem, attr) {
scope.states = [
{
id: "AL",
name: "Alabama"
},
{
id: "AK",
name: "Alaska"
},
{
id: "AS",
name: "American Samoa"
},
{
id: "AZ",
name: "Arizona"
},
{
id: "AR",
name: "Arkansas"
},
{
id: "CA",
name: "California"
},
{
id: "CO",
name: "Colorado"
}
]
scope.changeState = function (stateIndex) {
$http({
method:'GET',
url:'cities.json',
dataType:'jsonp'
}).success(function (cities) {
scope.cities = cities[stateIndex];
$rootScope.loading = false;
})
}
}
}
})
當我嘗試console.log($scope.$$schildHead)
返回null
但是當它成爲console.log($scope)
我發現$$schildHead
裏面並具有我所需要的屬性,
任何人都可以幫助。提前致謝!