2

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.

1
  • Can you provide the source of your example? Commented Oct 24, 2018 at 4:13

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.