后端提供了一个完全呈现的站点,并且在前端我希望angularjs通过ajax-call/data绑定来处理动态内容但是如果你传递指令ng-bind,那么angularjs会将它们直接绑定到它们的初始值,在任何之前为NULL用户行动.
我找到了一个hacky解决方案,但我想知道是否有一个更好的或者可能是另一个js框架,它正是我正在尝试做的事情:
https://github.com/herschel666/angular-lazy-bind
以下示例应该有助于理解我的问题...一旦js被加载,初始值"hola服务器端"(服务器端交付)消失了.我希望innerhtml/value保持这样,并保持绑定活动但是懒惰,这样它只会在一个动作后更改它,重要的是angularjs不重写已经写入的服务器端(redered)
<html ng-app="myApp">
<head>
<meta charset="UTF-8">
<title>Title of the document</title>
</head>
<body >
<div ng-controller="GreetingController">
<!-- this value has to stay ... but keep its binding property in order to change it afer an user action -->
<span ng-bind="greeting"> hola server side</span>
<button ng-click="update()">update</button>
</div>
</body>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.5/angular.min.js"></script>
<script type="text/javascript">
var myApp = angular.module('myApp',[]);
myApp.controller('GreetingController', ['$scope', function($scope) {
$scope.update = function (){
//do ajax calls and set greeting and other data to bind
$scope.greeting = 'Hola!';
} …Run Code Online (Sandbox Code Playgroud)