Benjamin W Benjamin W - 1 year ago 72
AngularJS Question

angularjs get template and pass variable to template

<section ng-app="app" ng-controller="ctrl">
<div id="output">{{ foo }}</div>
<button ng-click="myFun()">Click me</button>

var app = angular.module("app", []);
app.controller('ctrl', function($scope, $http){
$ = 123;
$scope.myFun = function(){
$ =;


<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?

Answer Source

I find another way to solve your question, i hope this sample helps you

 <html ng-app="app" ng-controller="ctrl">
<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", []);
        function ($scope) {
            $ = 123;

            $scope.myFun = function () {
                $scope.template = "temp.html";


<h1>{{ bar }}</h1>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download