Page does not work with Angular - doubt beginner

Asked

Viewed 48 times

0

I’m starting with Angular but it happens to me what always happens to those who are starting in the framework, but I’m not giving account. I can not do it works, I seem to have something imperceptible breaking the operation of the script and its execution on the page but I’ve tried everything see:

   var app = angular.module('loja',['ngRoute', 'ngResource']); //

app.controller('primeiroController', ['$scope', function($scope){

    $scope.objetoPessoa = 'Novo Valor';
    console.log($scope.objetoPessoa);

    $scope.getPorId = function(){

        console.log('fdsfsdgf');

    }

}]);

app.controller('pessoaController', ['$scope', '$resource', function($scope, $resource){

    pessoas = $resource("/bookstore_angular_spring/pessoas/?codPessoa=:codPessoa");

    $scope.getPorId = function(){

        console.log('fdsfsdgf');

        pessoas.get({codPessoa: $scope.codPessoa}, function(data){
            $scope.objetoPessoa = data;
        });
    }

}]);


app.config(function($routeProvider) {
    $routeProvider
    .when("/", {controller: "pegarResposta", templateUrl: "list.html"})
    .when("/edit/:name", {controller: "editController", templateUrl: "form.html"})
    .when("/new", {controller: "newController", templateUrl: "form.html"})
    .otherwise({redirectTo: "/"});
});

app.run(function($rootScope){
    $rootScope.frutas = ['banana', 'melancia', 'pera'];
});


app.controller('listController', ['$scope', function($scope){

}]);

In the html file I have:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html ng-app="loja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.5/angular.min.js"></script>

<script type="text/javascript" src="script/angular-resource.js"></script> 

<script type="text/javascript" src="script/angular-route.js"></script>
<!-- 
<script type="text/javascript" src="script/primeiroController.js"></script>
 -->
<script>

</script>
</head>
<body ng-controller="primeiroController" ng-init="objetoPessoa='burro'">

    <input type="text" ng-value="100" ng-model="codPessoa" />
    <hr>
    <button ng-click="getPorId();">Buscar por Id</button>
    <hr>
    <button ng-click="getTodos();">Budscar todos</button>
    <hr>
    <button ng-click="salvarPessoa();">Salvar pessoa</button>
    <hr>
    <button ng-click="deletarPessoa();">Deletar pessoa</button>
    <hr>

    <h1>{{objetoPessoa}}</h1>

</body>
</html>
  • The html header is: <html ng-app="shop"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.angular.min.js"></script> <script type="text/javascript" src="script/angular-Resource.js"></script> <script type="text/javascript" src="script/angular-route.js"></script> <! -- <script type="text/javascript" src="script/firstController.js"></script> -> <script>

  • Thank you Wictor Chaves for sorting the code of my post

1 answer

0

Missing the worthless ng-app attribute in the html tag, thanks for the replies

Browser other questions tagged

You are not signed in. Login or sign up in order to post.