I do not know how to use Component Angularjs

0

Good morning. I am working on a project of a web page where I use Angularjs.
The case is that they sent a controller where I use a .component and the template and I have no idea how it is done, I started doing something looking on the internet but it does not work that way. The thing is that when I open my page I see a bar above everything where an option that is called 'information' comes out, when I click on 'information I would have to show what I supposedly do with the .component.

I leave here all the code I am using.

The java script where I try to use the component:

    angular.module('formApp', ['ui.router']);

    angular.module('formApp').config(function ($stateProvider) {
    $stateProvider
        .state('informacion', {
            url: 'informacion',
            controller: 'InfoAppCtrl as form',
            templateUrl: '/scripts/templates/info.html'

         .component('AppForm', {
             template: '<div class="container text-center" style="padding-top:60px;" ui-view></div>'

         })
        })

});

Here I leave the driver that I made apart from the main one to create the template:

angular.module('formApp').controller('AppRespCtrl', function ($scope, $http) {

    var validarResp = this;
    validarResp.name = 'respuesta';
});

The HTML:

<h1>Template respuesta {{AppForm.name}}</h1>

And the Layout where I place the div so that it shows me what I said before:

<div class="container body-content">
        @RenderBody()
        @RenderSection("SPAViews", required: false)
        <hr />
        <footer>

            <div class="container text-center" style="padding-top:20px;" ui-view></div>
            <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>

        </footer>
    </div>
    
asked by SilviaGarcia 09.11.2016 в 13:15
source

1 answer

0

But this code that you put is wrong:

   angular.module('formApp', ['ui.router']);

    angular.module('formApp').config(function ($stateProvider) {
    $stateProvider
        .state('informacion', {
            url: 'informacion',
            controller: 'InfoAppCtrl as form',
            templateUrl: '/scripts/templates/info.html'

         .component('AppForm', {
             template: '<div class="container text-center" style="padding-top:60px;" ui-view></div>'

         })
        })

});

It should be something like this:

angular.module('formApp')
    .config(function($stateProvider) {
    $stateProvider
      .state('informacion', {
        url: 'informacion',
        controller: 'InfoAppCtrl as form',
        templateUrl: '/scripts/templates/info.html'
      });
  })
  .component('AppForm', {
    template: '<div class="container text-center" style="padding-top:60px;" ui-view></div>'
  });

Otherwise the components are almost the same as the usual directives, but with a couple of peculiarities. Todd Motto wrote a pretty clear article about the components , and the documentation is pretty good

I give you a jsfiddle so you can see how simple it is:

link

    
answered by 18.11.2016 в 10:28