-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexampleController.js
More file actions
73 lines (61 loc) · 2.33 KB
/
Copy pathexampleController.js
File metadata and controls
73 lines (61 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict';
/**
* Defined a controller named 'ExampleController' that works with the view template
* exampleTemplate.html. We assume that cs142App has already been defined by
* the main.js controller. To access this view need to include the controller:
*
* <script src="components/example/exampleController.js"></script>
*
* and its view template:
* <div ng-include="'components/example/exampleTemplate.html'" ng-controller="ExampleController"></div>
*/
cs142App.controller('ExampleController', ['$scope', function($scope) {
// $scope.main is defined if we are a child $scope of the main $scope in which
// case it contains the page's title property. We update it so the page title
// will include this view's name "Example".
$scope.onChange = function(mottoValue) {
if ($scope.main) {
$scope.main.onMottoChange(mottoValue);
}
};
if ($scope.main) {
$scope.main.title = 'CS142 Project #4 - Example';
}
/*
* The view template accesses there properties:
*
* testVariable = A string property that is displayed by the template. It demonstrates
* one-way binding from the scope to html.
*/
$scope.testVariable = 'Hello World';
/* textInput - A string property that is written by a input tag and displayed. It
* demonstrates the two-way binding of Angular
*/
$scope.textInput = '';
/* buttonWasClicked - A string property holding the name of the last button clicked.
* It is set the buttonClick() handler and read by the view template.
*/
$scope.buttonWasClicked = '';
/*
* buttonClick - The handler function called when a button is clicked. It is passed
* the button name.
*/
$scope.buttonClick = function(buttonName) {
$scope.buttonWasClicked = buttonName;
};
/*
* name - We read the example model data into the scope variable 'name'
*/
$scope.name = window.cs142models.exampleModel().name;
if ($scope.main) {
$scope.main.name = $scope.name;
}
/*
$scope.changeView = function() {
var ele = angular.element( document.querySelector( '.dynamicView' ) );
ele.empty();
var url = "components/states/statesTemplate.html";
var innerHTML = "<div ng-include='" + url + "' ng-controller='StatesController'></div>";
ele.append(innerHTML);
}*/
}]);