PenVirus PenVirus - 1 year ago 66
AngularJS Question

UI-Router controller isn't working

I'm new to using UI-Router, and I'm struggling to get this controller working. The view loads, but the function doesn't trigger on ng-click. JSFiddle

var app = angular.module('app', ['ui.router']);

app.controller('dashboardCtrl', [
$scope.testFunction = function(){

app.config(function ($stateProvider, $urlRouterProvider){
$stateProvider.state("dashboard", {
url: "#",
templateUrl: "dashboard.html",
controller: "dashboardCtrl"


<body ng-app="app">
<a ui-sref="dashboard">Dashboard</a>

<script type = "text/ng-template" id = "dashboard.html">
<button ng-click="testfunction()">Click</button>

Answer Source

The testfunction in your template not working because there no function in controller called testfunction. In controller you specified it as testFunction. Note the capital letter 'F' in it. It will work if you change it. but, please not that url: "#" is not valid URL

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download