-
-
Save anonymoussc/eb600852490ec5332277 to your computer and use it in GitHub Desktop.
Making an Update to the Scope
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html ng-app="exampleApp"> | |
<head> | |
<title>Controllers</title> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css"> | |
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script> | |
<script> | |
angular.module("exampleApp", []) | |
.controller("simpleCtrl", function($scope) { | |
$scope.cities = ["London", "New York", "Paris"]; | |
$scope.city = "London"; | |
$scope.getCountry = function(city) { | |
switch (city) { | |
case "London": | |
return "UK"; | |
case "New York": | |
return "USA"; | |
} | |
} | |
}); | |
</script> | |
</head> | |
<body ng-controller="simpleCtrl"> | |
<div class="well"> | |
<label>Select a City:</label> | |
<select ng-options="city for city in cities" ng-model="city"></select> | |
</div> | |
<div class="well"> | |
<p>The city is: {{city}}</p> | |
<p>The country is: {{getCountry(city) || "Unknown"}}</p> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment