javascript – 如何用函数更改ng-init值?

前端之家收集整理的这篇文章主要介绍了javascript – 如何用函数更改ng-init值?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

这是我的HtmlJavaScript代码,我想通过函数更改它.

HTML:

JavaScript的:

  1. function item(id,name) {
  2. this.id = id;
  3. this.name = name;
  4. };
  5. angular.module('myApp',[]).controller('myController',function($scope) {
  6. $scope.items = [];
  7. $scope.makeVisible = "";
  8. $scope.initItems = function() {
  9. $scope.items.push(new item("0",'Vikash'));
  10. $scope.items.push(new item("1",'Kumar'));
  11. $scope.items.push(new item("2",'Vishal'));
  12. $scope.items.push(new item("3",'Ajay'));
  13. };
  14. $scope.renameThis = function(index,oldValue) {
  15. console.log("oldValue==" + oldValue);
  16. console.log("indexx==" + index);
  17. var id = 'Box-' + index;
  18. console.log("Id : " + id);
  19. document.getElementById(id).style.display = "block";
  20. console.log('jai hind');
  21. };
  22. $scope.showme = function(id) {
  23. $scope.makeVisible = id;
  24. console.log('id',id);
  25. };
  26. $scope.hideme = function(id) {
  27. console.log(item);
  28. $scope.makeVisible = "";
  29. };
  30. $scope.title = 'Enter new name here';
  31. $scope.rename = function() {
  32. $scope.item.name = $scope.newname;
  33. console.log('dfasdd');
  34. };
  35. });

这是ng-init中的值,它在输入框1中显示,我想在点击时用第二个输入框的值更改它.我怎样才能做到这一点?
我还在按钮上添加了一个功能.

最佳答案
在项目中添加可见的attr,

  1. function item(id,name) {
  2. this.id = id;
  3. this.visible=false;
  4. this.name = name;
  5. }

并将显示和隐藏功能更改为此代码

  1. $scope.hideme = function(item) {
  2. item.visible=false;
  3. };
  4. $scope.showme = function(item) {
  5. item.visible=true;
  6. };

并更改此代码

至:

并将项目对象发送到shomme和hideme函数

猜你在找的JavaScript相关文章