How to use angularjs and mustache -
i found directive , want use display variable angularjs , compile mustache.
var myapp = angular.module('demoapp', []); myapp.directive('jnhmustache', [function () { var declaration = {}; declaration.restrict = 'e'; declaration.scope = { data : '&', watch : '=' }; declaration.transclude = false; declaration.link = function (scope, element, attrs) { function render () { var html = mustache.render(scope.template, scope.data()); element.html(html); }; scope.template = element.html(); element.html(''); scope.$watch(function () { var result = scope.data()[scope.watch].length; return result; }, function () { render(); }, false); }; return declaration; }]); myapp.controller('examplecontroller', function ($scope) { $scope.mydata = { name: 'jon hartmann'}; $scope.watching = 'name'; }); <div ng-app="demoapp"> <div ng-controller="examplecontroller"> <jnh-mustache data="mydata" watch="watching"> <div ng-non-bindable> <h1>{{name}}</h1> </div> </jnh-mustache> </div> </div>
i have problem when want create variable inside controller , display mustache such as:
$scope.somedata = 'name'; <jnh-mustache data="mydata" watch="watching"> <div ng-non-bindable> <h1>{{somedata}}</h1> </div> </jnh-mustache>
this display nothing don't know fix
Comments
Post a Comment