Haml的意见Rails应用程序内使用AngularJS [英] Using AngularJS within Haml views of a Rails app

查看:190
本文介绍了Haml的意见Rails应用程序内使用AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Haml的意见Rails应用程序。现在我想AngularJS添加到应用程序的某些部分,但问题是,Haml的观点被渲染服务器端和AngularJS code是不工作的,因为它呈现的客户端。

I have a Rails app with Haml views. Now I want to add AngularJS to some parts of the application, but the problem is that the Haml views are rendered server-side and the AngularJS code is not working, because it is rendered client-side.

让我们说我有这只是在我的index.html.haml:

Let's say I have just this in my index.html.haml:

!!!
%html{"ng-app" => "Test"}
  %head
    %script{:src => "http://ajax.googleapis.com/ajax/libs/angularjs/1.0.3/angular.js"}
    :javascript
      function Clock($scope) {
        $scope.currentTime = new Date();
      }
    %title Welcome to AngularJS
  %body
    %h1 Hello, World.
    %p{"ng-controller" => "Clock"}
      The current time is {{currentTime | date:'h:mm:ss a'}}.

所以目前,它只是打印出大括号中的一切,而不实际处理它。有解决方案,但他们对您的完整视图是由AngularJS模板更换的情况。我想主要使用AngularJS在我的Rails应用程序的功能小位。任何想法如何解决这个问题?

So currently, it's just printing out everything within the curly brackets without actually processing it. There are solutions but they for situations where your complete view is replaced by an AngularJS template. I want to use AngularJS mainly for small bits of functionality in my Rails app. Any ideas how to solve this?

推荐答案

约翰,

我在这里编辑您的codeA位:的http:// codePEN .IO /匿名/笔/ vKiwH

I have edited your code a bit here: http://codepen.io/anon/pen/vKiwH

%html{"ng-app"=>true}
 %p{"ng-controller" => "clock"}
  The current time is {{currentTime | date:'h:mm:ss a'}}.

和JavaScript是:

and the javascript is:

function clock($scope) {
  $scope.currentTime = new Date().getTime();
}

这篇关于Haml的意见Rails应用程序内使用AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆