我为一个模块使用了2个控制器。我想根据为模块定义的控制器执行单独的操作。我没有得到第二个控制器的预期输出。
请找到以下方法有意义。
var helloApp = angular.module("helloApp", []);
helloApp.controller("CompanyCtrl", function($scope) {
$scope.companies = [
{ 'companyName':'Infi',
'Level': 1,
'Created': 'Bangalore','Status': 'In Progress'},
{ 'companyName':'Cogi',
'Level': 1,
'Created': 'Bangalore','Status': 'In Progress'},
{ 'companyName':'Infosys Technologies',
'Level': 1,
'Created': 'Bangalore','Status': 'In Progress'},
{ 'companyName':'Infosys Technologies',
'Level': 1,
'Created': 'Bangalore','Status': 'In Progress'},
{ 'companyName':'Infosys Technologies',
'Level': 1,
'Created': 'Bangalore','Status': 'In Progress'},
];
});
helloApp.controller("SectionController", function($scope) {
$scope.rightsection = [
{ 'Topic':'Bobs Pizza',
'Comment': 'Raw denim you probably havent heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache ' },
{ 'Topic':'Bill`s Jugs',
'Comment': 'Raw denim you probably havent heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache '},
{ 'Topic':'Bobs Pizza',
'Comment': 'Raw denim you probably havent heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache '},
{ 'Topic':'Bill`s Jugs',
'Comment': 'Raw denim you probably havent heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache '},
{ 'Topic':'Bobs Pizza',
'Comment': 'Raw denim you probably havent heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache '}
];
});
当我尝试使用第二个控制器时,(下方)我没有看到页面上显示的任何内容。上面的方法是错的吗?如果是这样,我如何将两个控制器添加到单个模块?请帮帮我。
<div class="right" ng-controller="SectionController">
<table class="table" id="tl" ng-repeat="section in rightSection">
<tr>
<th>Company Name
</th>
</tr>
<tr>
<td>{{section.Topic}}
</td>
</tr>
</table>
</div>
答案 0 :(得分:1)
您对rightSection
的迭代和范围变量rightsection
(区分大小写)。
答案 1 :(得分:0)
看看这个。在div中,您不要将ng-app属性和更改de var范围名称添加到rightSection。
var helloApp = angular.module("helloApp", []);
helloApp.controller("CompanyCtrl", function($scope) {
$scope.companies = [{
'companyName': 'Infi',
'Level': 1,
'Created': 'Bangalore',
'Status': 'In Progress'
}, {
'companyName': 'Cogi',
'Level': 1,
'Created': 'Bangalore',
'Status': 'In Progress'
}, {
'companyName': 'Infosys Technologies',
'Level': 1,
'Created': 'Bangalore',
'Status': 'In Progress'
}, {
'companyName': 'Infosys Technologies',
'Level': 1,
'Created': 'Bangalore',
'Status': 'In Progress'
}, {
'companyName': 'Infosys Technologies',
'Level': 1,
'Created': 'Bangalore',
'Status': 'In Progress'
}, ];
});
helloApp.controller("SectionController", function($scope) {
$scope.rightSection = [{
'Topic': 'Bobs Pizza',
'Comment': 'Raw denim you probably havent heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache '
}, {
'Topic': 'Bill`s Jugs',
'Comment': 'Raw denim you probably havent heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache '
}, {
'Topic': 'Bobs Pizza',
'Comment': 'Raw denim you probably havent heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache '
}, {
'Topic': 'Bill`s Jugs',
'Comment': 'Raw denim you probably havent heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache '
}, {
'Topic': 'Bobs Pizza',
'Comment': 'Raw denim you probably havent heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache '
}];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div class="right" ng-app="helloApp" ng-controller="SectionController">
<table class="table" id="tl" ng-repeat="section in rightSection">
<tr>
<th>Company Name
</th>
</tr>
<tr>
<td>{{section.Topic}}
</td>
</tr>
</table>
</div>