Reputation: 2848
<section ng-app="app" ng-controller="ctrl">
<div id="output">{{ foo }}</div>
<button ng-click="myFun()">Click me</button>
</section>
var app = angular.module("app", []);
app.controller('ctrl', function($scope, $http){
$scope.bar = 123;
$scope.myFun = function(){
$http.get('template.html').then(function(response){
$scope.foo = response.data;
});
};
});
//template
<h1>{{ bar }}</h1>
I'm new in angularjs
I try to create a ng-click and get a template data into page like ajax
I try to use variable inside of template
anyone know how to pass variable to template in angularjs?
Upvotes: 1
Views: 1199
Reputation: 2547
I find another way to solve your question, i hope this sample helps you
<html ng-app="app" ng-controller="ctrl">
<head>
<title>sample</title>
</head>
<body>
<div ng-include="template"></div>
<button ng-click="myFun()">Click me</button>
<script src="angular.js"></script>
<script type="text/javascript">
var app = angular.module("app", []);
app.controller("ctrl",
function ($scope) {
$scope.bar = 123;
$scope.myFun = function () {
$scope.template = "temp.html";
};
});
</script>
Template
<h1>{{ bar }}</h1>
Upvotes: 1