我尝试使用angularjs和bootsrap编写应用程序。我在服务器,SLIM和CoffeeScript上使用RoR来获取模板和资产。这是我的索引文件:
doctype
html lang="en" ng-app='my_server'
head
meta charset="utf-8"
meta content="IE=Edge,chrome=1" http-equiv="X-UA-Compatible"
title= content_for?(:title) ? yield(:title) : "MyServer"
= csrf_meta_tags
= stylesheet_link_tag "application", :media => "all"
= favicon_link_tag
= javascript_include_tag "application"
body
.navbar.navbar-fluid-top
.navbar-inner
.container-fluid
a.btn.btn-navbar data-target=".nav-collapse" data-toggle="collapse"
span.icon-bar
span.icon-bar
span.icon-bar
a.brand href="#" My server
.container-fluid.nav-collapse
ul.nav
li= link_to "Link1", "/path1"
li= link_to "Link2", "/path2"
li= link_to "Link3", "/path3"
/! /.nav-collapse
.container-fluid
.container-fluid(ng-view)
footer
p © Company 2013
/! /container
app.js.coffee:
@app = angular.module('my_server', [])
.config(['$routeProvider', ($routeProvider) -> @RouteProvider($routeProvider)])
.run(['$rootScope', '$location', ($rootScope, $location) ->
])
routes.js.coffee:
@RouteProvider = ($routeProvider) ->
$routeProvider.when('/sign_in', {templateUrl: 'assets/sign_in.html', controller: SignInController})
sign_in_controller.js.coffee:
@SignInController = ($scope, $routeParams) ->
alert("Controller loaded")
Auth = ->
alert("Auth")
并且sign_in.html.slim,动态加载(我修改了rails资产管道配置,因此我可以将SLIM用于静态页面):
.body
form
fieldset
legeng Sign in
label
input type='email' placeholder='email' ng-model='email'
label
input type='password' placeholder='password' ng-model='password'
button.btn ng-click='Auth()' Auth
当我试图继续/#/ sign_in时,我看到我的身份验证表单,我看到“控制器已加载”消息的警报,所以我认为SignInController已加载。但是当我按下我的表格上的Auth按钮时,我看不到带有“Auth”消息的警报,即控制器方法Auth没有被调用。当我试图在SignInController
中写这样的东西时$scope.email = 'email@example.com
我在表单中看不到此电子邮件。我在浏览器控制台中没有错误或警告。
为什么我的部分表格看不到我的控制器?我做错了什么?
更新
控制器方法必须定义为$ scope properties
答案 0 :(得分:0)
Auth方法需要是范围属性。尝试更改
Auth = ->
alert("Auth")
到
$scope.Auth = ->
alert("Auth")