mvmthecreator mvmthecreator - 1 year ago 56
AngularJS Question

Angularjs push array to scope

I have problems to push an array to scope and empty the array after that.

I fire up the function

to add a new form to the Array
$ = [];
wich contains an another array

If i click the
again the form will be generated but is filled in with data already. Means the same values on every meta_keys:$scope.tags. I think i need to empty the array before generate new.
Or i am on the wrong way. thanks for help.


<div ng-app="myApp" ng-controller="myCtrl">

<div class="form-group">
<label for="txtDevice" class="control-label">Domain Name:</label>
<input type="text" class="form-control" ng-model="" id="txtDevice">
<div class="form-group">
<label for="txtIP" class="control-label">IP Address:</label>
<input type="text" class="form-control" ng-model="info.ip" id="txtIP">
<div class="form-group">
<label for="txtUsername" class="control-label">Logo:</label>
<input type="text" class="form-control" ng-model="info.logo" id="txtLogo">

<div class="form-group" ng-repeat="site in info.sites track by $index">
<h4>Seite {{$index+1}}</h4>
<label type="txt" class="control-label">Title</label>
<input type="txt" class="form-control" ng-model="site.site_title" /><br />
<label type="txt" class="control-label">Desc</label>
<input type="text" class="form-control" ng-model="site.meta_desc"><br />
<label type="txt" class="control-label">Meta Keys</label>
<!-- <input type="text" class="form-control" ng-model="site.meta_keys"> -->
<tags-input ng-model="tags" ></tags-input>

<button ng-click="addInput()">+add more inputs</button>
{{info | json}}

tags = {{tags | json}}



angular.module('myApp', ['ngTagsInput'])
.controller('myCtrl', function($scope, $http){
$ ="myName" ;
$ = {};
$ = [];
$scope.tags = [];

$scope.addInput = function() {
//$scope.tags = [];

// $ = [];


Answer Source

Just replace the line

<tags-input ng-model="tags" ></tags-input>


<tags-input ng-model="site.tags" ></tags-input>

I hope, it helps :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download