微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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函数

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐