Javascript 使用angularjs实现时未显示行
表中添加了空行,但在模式弹出窗体中输入值后,行值没有反映出来 这是我已经添加了ng controller=“compctrl”的html片段 这是我为在表中添加值而创建的自定义控制器“compctrl”Javascript 使用angularjs实现时未显示行,javascript,angularjs,Javascript,Angularjs,表中添加了空行,但在模式弹出窗体中输入值后,行值没有反映出来 这是我已经添加了ng controller=“compctrl”的html片段 这是我为在表中添加值而创建的自定义控制器“compctrl” MetronicApp.controller('compctrl', ['$rootScope', '$scope', 'settings', function($rootScope, $scope, settings) { $scope.$on('$viewContentLoaded'
MetronicApp.controller('compctrl', ['$rootScope', '$scope', 'settings', function($rootScope, $scope, settings) {
$scope.$on('$viewContentLoaded', function() {
$scope.companies = [
{ 'name':'Infosys Technologies',
'strength': 125000,
'location': 'Bangalore'},
{ 'name':'Cognizant Technologies',
'strength': 100000,
'location': 'Bangalore'},
{ 'name':'Wipro',
'strength': 115000,
'location': 'Bangalore'},
{ 'name':'Tata Consultancy Services (TCS)',
'strength': 150000,
'location': 'Bangalore'},
{ 'name':'HCL Technologies',
'strength': 90000,
'location': 'Noida'},
];
$scope.addRow = function(){
$scope.companies.push({ 'name':$scope.name, 'strength': $scope.strength, 'location':$scope.location });
$scope.name='';
$scope.strength='';
$scope.location='';
};
// initialize core components
Metronic.initAjax();
});
}]);
我想通知您,我正在使用Metronic主题。但当我以模态形式输入值时,它不会被添加到一行中。只会出现空行。这可能是因为控制器(模板)和模态的范围问题。尝试使用$rootscope或尝试将值从模式广播到控制器,然后将其从控制器推送到$scope.companys中。这可能是因为控制器(模板)和模式的范围问题。尝试使用$rootscope或尝试将值从模式广播到控制器,然后将其从控制器推入$scope.companys。这可能是因为您正在清除$scope.name、$scope.strength和$scope.location。尝试先将值放入一个var中,然后使用它来分配它<代码>变量名称=$scope.name$scope.companys.push({'name':name})代码>无效。请给我一个替代解决方案。这可能是因为您正在清除$scope.name、$scope.strength和$scope.location。尝试先将值放入一个var中,然后使用它来分配它<代码>变量名称=$scope.name$scope.companys.push({'name':name})代码>它不工作。请给我一个替代解决方案。
.state('myDatatablesAdvanced', {
url: "/datatables/deepdiscount1",
templateUrl: "views/datatables/deepdiscount1.html",
data: {pageTitle: 'Advanced Datatables', pageSubTitle: 'advanced datatables samples'},
controller: "compctrl",
resolve: {
deps: ['$ocLazyLoad', function($ocLazyLoad) {
return $ocLazyLoad.load({
name: 'MetronicApp',
insertBefore: '#ng_load_plugins_before', // load the above css files before '#ng_load_plugins_before'
files: [
'../../../assets/global/plugins/select2/select2.css',
'../../../assets/global/plugins/datatables/plugins/bootstrap/dataTables.bootstrap.css',
'../../../assets/global/plugins/datatables/extensions/Scroller/css/dataTables.scroller.min.css',
'../../../assets/global/plugins/datatables/extensions/ColReorder/css/dataTables.colReorder.min.css',
'../../../assets/global/plugins/select2/select2.min.js',
'../../../assets/global/plugins/datatables/all.min.js',
'js/scripts/table-advanced.js',
'js/controllers/tab.js'
]
});
}]
}
})
MetronicApp.controller('compctrl', ['$rootScope', '$scope', 'settings', function($rootScope, $scope, settings) {
$scope.$on('$viewContentLoaded', function() {
$scope.companies = [
{ 'name':'Infosys Technologies',
'strength': 125000,
'location': 'Bangalore'},
{ 'name':'Cognizant Technologies',
'strength': 100000,
'location': 'Bangalore'},
{ 'name':'Wipro',
'strength': 115000,
'location': 'Bangalore'},
{ 'name':'Tata Consultancy Services (TCS)',
'strength': 150000,
'location': 'Bangalore'},
{ 'name':'HCL Technologies',
'strength': 90000,
'location': 'Noida'},
];
$scope.addRow = function(){
$scope.companies.push({ 'name':$scope.name, 'strength': $scope.strength, 'location':$scope.location });
$scope.name='';
$scope.strength='';
$scope.location='';
};
// initialize core components
Metronic.initAjax();
});
}]);