Tuesday, February 9, 2016

define controller as vm to no longer inject $scope


<!DOCTYPE html>
<html>
<head>
    <title>test</title>
<meta charset="utf-8" />
    <script src="scripts/angular.js"></script>
    <script src="scripts/app.js"></script>
</head>
<body>
    <div ng-app="musicApp">
    <div ng-controller="ArtistController as vm">
        {{vm.name}}
 
    </div>
</div>
</body>
</html>


var app = angular.module("musicApp", []);
app.controller('ArtistController', [artistController]);
function artistController() {
    var vm = this;
    vm.name = 'Foo';
};

1 comment:

  1. I found this article easy to understand and very helpful. Can’t wait to see the other posts. Thank you for sharing!


    Melbourne SEO Service

    ReplyDelete