受到嵌套控制器的攻击。此代码的主要目的是将从.json超链接提取的数据提取到另一个文件/函数。
.html文件:
<div ng-app="myApp" ng-controller="GetCtrl" >
<li ng-controller="ChannelCtrl" ng-repeat="x in Operator">
<a href="getChannels({{x.OP_Name}})" > {{ x.OP_Name}} <br/></a>
</li></div>`
app.js:
app.controller('GetCtrl', function($scope, $http) {
$http.get('partials/operator.json')
.then(function (response) {$scope.Operator = response.data.Operator;});
});
app.service('ChannelList', function () {
this.getChannels = function(chname) {
document.write("In Idea");
}
});
app.controller('ChannelCtrl',function($scope,$http,ChannelList) {
ChannelList.getChannels();
});
.json文件:
{
"Operator" : [
{"OP_Name":"IDEA"},
{"OP_Name":"VODAFONE"},
{"OP_Name":"AIRTEL"},
{"OP_Name":"BSNL"},
{"OP_Name":"DOCOMO"},
{"OP_Name":"AIRCEL"},
{"OP_Name":"DIALOG"}
]
}
我面临的问题是只有一个控制器正在运行。我无法使用这两个控制器,因此我的输出不完整。 我可以调用该函数以及显示.json文件的内容。但是我无法一次执行这两个操作。
输出必须如下:
.Idea
.Airtel
.
.
.
当我点击其中一个超链接时,必须调用getchannels()函数。
答案 0 :(得分:0)
要调用控制器功能,您可能需要使用ng-click,并且无法使用href调用控制器功能。
<a href="#" ng-click="getChannels(x.OP_Name)"> {{ x.OP_Name}}</a><br/>