在main.view.html内我有按钮编辑:
<md-button class="md-raised md-primary" ng-click="redirectEdit($index)" >Edit</md-button>
redirectEdit($index)
,它在main.controller.js中获取当前行的索引(有值),如下所示:
$scope.redirectEdit = function(index){
$scope.all[index];
window.location = "../ang/#!/edit";
$scope.name =$scope.all[index].name;
$scope.surname =$scope.all[index].surname;
$scope.email =$scope.all[index].email;
$scope.review =$scope.all[index].review;
};
使用此方法我想将用户重定向到编辑表单并将这些特定的内容输入到输入字段中。
First Name: <input type="text" ng-model="name" >
我试过这样做,但那不起作用
答案 0 :(得分:0)
查看您的方案,我建议您使用$emit
和$on
。同时创建所有字段的对象,例如$scope.formFields = {};
$scope.redirectEdit = function(index){
$scope.all[index];
$scope.formFields = {};
$scope.formFields.name =$scope.all[index].name;
$scope.formFields.surname =$scope.all[index].surname;
$scope.formFields.email =$scope.all[index].email;
$scope.formFields.review =$scope.all[index].review;
$scope.$emit('userData', {data: $scope.formFields}); //to set the value
window.location = "../ang/#!/edit";
};
在editController.js上获取数据并相应地将值赋给ng-model
$rootScope.$on('userData', function (event, data) {}); // to get the value
我希望这会有所帮助