I'm new to angularJs, I have been working in an example using angular ui router. can anyone please let me know if you see any error? I'm using Visual Studio.

index.cs html

<body>
    <div ng-app="app">
        First Name: <input type="text" ng-model="firstName"><br>
        Last Name: <input type="text" ng-model="lastName"><br>
        <br>
        Full Name: {{firstName + " " + lastName}}
    </div>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.7.5/angular.min.js" ></script>
    <script src="https://unpkg.com/@uirouter/[email protected]/release/angular-ui-router.min.js"></script>
    <script src="~/App/application.js"></script>
        <script src="~/App/Controlers/controller.js"></script>

</body>
</html>

application.js

var app = angular.module("app",
            ["ui.router"]);
    app.config(function ($stateProvider, $urlRouterProvider) {


    $urlRouterProvider.otherwise('/home');

    $stateProvider
        // State managing 
        .state('home', {
            url: '/home',
            templateUrl: '/home/index',
            controller: 'myCtrl'
        })
        .state('home.index', {
            url: '/',
            controller: 'myCtrl'
        });

});

controller.js

app.controller('myCtrl', function ($scope) {
            $scope.firstName = "John";
            $scope.lastName = "Doe";
        });

I'm using localhost/Home/Index/ the application is working fine, but the default values for "firstName" or "lastName" is not working.

  • Can you provide the source of your example? – holydragon 22 hours ago
up vote 0 down vote accepted

I put your codes into a Plunker. The only thing I changed is the <script> tags.

I moved them into header tag and removed

<script src="~/App/application.js"></script>
<script src="~/App/Controlers/controller.js"></script>

and added

<script src="app.js"></script>

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.