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

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

HTML:

JavaScript的:

function item(id,name) {
    this.id = id;
    this.name = name;
};

angular.module('myApp',[]).controller('myController',function($scope) {
    $scope.items = [];
    $scope.makeVisible = "";
    $scope.initItems = function() {
        $scope.items.push(new item("0",'Vikash'));
        $scope.items.push(new item("1",'Kumar'));
        $scope.items.push(new item("2",'Vishal'));
        $scope.items.push(new item("3",'Ajay'));
    };
    $scope.renameThis = function(index,oldValue) {
        console.log("oldValue==" + oldValue);
        console.log("indexx==" + index);
        var id = 'box-' + index;
        console.log("Id : " + id);
        document.getElementById(id).style.display = "block";
        console.log('jai hind');
    };
    $scope.showme = function(id) {
        $scope.makeVisible = id;
        console.log('id',id);
    };
    $scope.hideme = function(id) {
        console.log(item);
        $scope.makeVisible = "";
    };
    $scope.title = 'Enter new name here';
    $scope.rename = function() {
        $scope.item.name = $scope.newname;
        console.log('dfasdd');
    };
});

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

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

function item(id,name) {
    this.id = id;
    this.visible=false;
    this.name = name;
}

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

$scope.hideme = function(item) {
     item.visible=false;
};

$scope.showme = function(item) {
     item.visible=true;
};

并更改此代码

至:

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

相关文章

kindeditor4.x代码高亮功能默认使用的是prettify插件,prett...
这一篇我将介绍如何让kindeditor4.x整合SyntaxHighlighter代...
js如何实现弹出form提交表单?(图文+视频)
js怎么获取复选框选中的值
js如何实现倒计时跳转页面
如何用js控制图片放大缩小