2017-09-13 79 views
0

我有一个名为$ rootScope.dataAngularJS来自内部的对象

```

$rootScope.data = { 
     model: 'build', 
     availableOptions: [ 
      { logo: 'https://tctechcrunch2011.files.wordpress.com/2013/04/balanced- 
       e28093c2a0logo.png', 
       name: 'Balanced' 
      } 
     ] 
    } 

```

对象获取属性里面阵列I与视图中显示它:

```

​​

```

和推功能是:

```

$scope.addGateway =() => { 
     console.log($scope.data.model) 
     $scope.gateways.push({ 
      logo: $scope.data.model, 
      status: 'ENABLED', 
      statusColor: 'green-darken-1' 
     }) 
    } 

```

然后我有一个按钮,推入一个新的数组,它确实我想要它做什么:推动公司的标志。但我不知道如何访问中的name或将其推送到新阵列。

我使用的AngularUI Bootstrap的方式,所以推功能是在另一个控制器。

+0

从哪里得到'name'? – Rahul

回答

0

我可能只是饿了。哈哈。吃完之后,我又进去再次编码,我很笨,我第一次没有得到它:

const checkForSame =() => { 
    for (let i = 0; i < gateways.length; i++) { 
     $scope.test = gateways[i].name 
     if ($scope.data.model == $scope.test) { 
      console.log('same!') 
      return 
     } 
     else { 
      console.log('not same!') 
      return 
     } 
    } 
    return 
}