2017-06-05 65 views
3

我试图学习与Pug和SCSS同时使用Angular,我当前的问题是与ng-class概念。我的代码如下:使用Pug和SCSS与Angular(ng-model)

HTML(在帕格)

form 
    input#theSearch(type='text' ng-model="theSearch") 
    br 
    span(ng-class ="{'test': isEven()}") Example Text 

SCSS

.test { 
    color:red; 
    font-size:80px; 
} 

AngularJS

angular.module("root", []) 
    .controller("index",["$scope",function($scope) { 
    $scope.theSearch = 1; 
    $scope.isEven = function() { return $scope.theSearch % 2 === 0; }; 
}]); 

小号o理想情况下,当用户输入一个偶数并将红色变为红色以及增加尺寸时,这会发生反应。目前,即使有投入,它也不会改变。我怀疑这是一些菜鸟的语法错误,但任何关于这个问题的指导都将非常感激。

附注: 我在CodePen环境中。包括Pug,包含SCSS,包含Bootstrap,正在使用Angular 1.6.1。所有的html都包含在main.container-fluid(ng-app="root")中。先谢谢你!

+1

你会得到任何错误?你发布的模块工作正常https://codepen.io/srajagop/pen/KqwEJP。 – karthick

+0

你能分享你的笔吗? – karthick

+0

感谢您的codepen!回答如下。谢谢! –

回答

1

感谢karthick发布的codePen!我的HTML在form元素上缺少ng-controller="index"。没有控制器,$scope不知道在哪里应用(我相信)。再次感谢karthick!