我的HTML不能從子控制器存取權限父控制器的方法
<section class="localsContainer" ng-controller="LocalsCtrl">
<h3>Lokale</h3>
<div class="placesProgress"></div>
<ul>
<li ng-repeat="city in cities">
<p ng-show="city.LocalCount > 0" ng-click="getLocals(city.Id)">{{city.Name}}</p>
<ul ng-show="activeCityLeft === city.Id">
<li ng-repeat="local in locals[city.Id]">
<p>{{local.Name}} ng-click="getDetails()"</p>
</li>
</ul>
</li>
<li ng-if="cities.length == 0">
<strong>Nie znaleziono</strong>
</li>
</ul>
</section>
和js
angular.module('sandboxApp')
.controller('MainCtrl', function ($scope, API) {
API.newRequest('getCitiesList').success(function (data, status, headers, config) {
$scope.cities = data.data;
});
$scope.getDetails = function() {
console.log("test")
};
})
.controller('LocalsCtrl', function ($scope, API) {
$scope.locals = {};
$scope.getLocals = function (cityid) {
$scope.activeCityLeft = cityid;
API.newRequest('getLocalList', { params: { 'city_id': cityid.toString() }, cache: true }).success(function (data, status, headers, config) {
$scope.locals[cityid] = data.data;
});
};
})
如果我理解正確的話,我應該能夠援引「getDetails」的方法在任何地方,因爲它是在主控制器上定義,即使是獲取其控制器的元素,但嵌套在與主控制器相連的元素中。但它不起作用,當我點擊應該調用getDetails的元素,而是顯示'ng-click ='getDetails()'作爲html文本。
屬性必須的元素,例如上'
' – Clive 2014-12-13 12:14:33