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

前端之家收集整理的这篇文章主要介绍了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函数

原文链接:https://www.f2er.com/js/429028.html

猜你在找的JavaScript相关文章