0
I’m doing a basic forum just for testing, I’m using the mongo
and postman
to add some things for testing. However, now, I want from the page, I send such data.
Use of http://localhost:3000/topico/cadastrar
to add the items.
Follow the codes made so far with some modifications, using as an example on this site http://tableless.com.br/criando-uma-aplicacao-simples-com-angularjs/
$scope.adicionaItem = function () {
$scope.itens.push({titulo: $scope.item.titulo, assunto: $scope.item.assunto, descricao: $scope.item.descricao});
//$scope.item.produto = $scope.item.quantidade = '';
toastr.success("Tópico Adicionado com Sucesso");
};
describe('Lista Compras Unitário', function () {
describe('ListaComprasController', function () {
beforeEach(function () {
this.$scope = {};
this.controller = new ListaComprasController(this.$scope);
});
it('deve criar "itens" com 2 ítens', function () {
expect(this.$scope.itens.length).toBe(2);
});
describe('adicionaItem', function () {
it('deve adicionar um novo ítem à lista com dados do escopo', function () {
this.$scope.item = {};
this.$scope.item.titulo;
this.$scope.item.assunto;
this.$scope.item.descricao;
this.$scope.adicionaItem();
expect(this.$scope.itens.length).toBe(3);
expect(this.$scope.itens[2].titulo).toBe('Carne');
expect(this.$scope.itens[2].assunto).toBe(5);
expect(this.$scope.itens[2].descricao).toBeFalse;
});
});
});
});
html:
<form class="form-horizontal">
<div class="form-group">
<label for="titulo" class="col-sm-2 control-label">Titulo</label>
<div class="col-sm-8">
<input type="text" class="form-control" id="titulo" placeholder="Titulo da sua questão, seja especifico" ng-model=" item.titulo" required>
</div></div>
<div class="form-group">
<label class="col-md-2 control-label" for="selectbasic">Assunto:</label>
<div class="col-md-3">
<select id="tipos" name="" class="form-control" ng-model=" item.assunto" required>
<option value="ensino">Ensino</option>
<option value="saude">Saúde</option>
<option value="trabalho">Mercado de Trabalho</option>
<option value="lazer">Lazer</option>
<option value="trabalho">Compras</option>
<option value="outros">Outros</option>
</select>
</div>
</div>
<div class="form-group">
<label class="col-md-2 control-label" for="textarea"></label>
<div class="col-md-7">
<textarea class="form-control" id="descricao" name="descricao" rows=5 ng-model=" item.descricao" required></textarea>
</div>
</div>
<br>
<center><button type="submit" class="btn btn-info ng-click="adicionaItem()"> Criar Tópico</button></center>
Hello Mayla, could inform the problem?
– Hiago Souza
Hello Hiago, so I don’t know how/where to put the localhost to send the data I type in the page go to API
– Mayla Campos
vc want to insert 1 item and send, or want to fill in an array to send?
– Hiago Souza
To call the api you will need to use $http https://docs.angularjs.org/api/ng/service/$http
– Hiago Souza
Submit the topic items (title, subject and description). I will take a look at the link
– Mayla Campos